小编chr*_*dev的帖子

Web API中的多个GET调用错误操作

我有一个Web API,看起来像以下......

public class LeaguesController : ApiController
{
    //api/Leagues/active/1
    //api/Leagues/complete/1
    //api/Leagues/both/1
    [GET("api/Leagues/{type}/{id}")]
    public List<Competition> Get([FromUri]int id, 
                                [FromUri]CompetitionManager.MiniLeagueType type)
    {
        return CompetitionManager.GetUsersMiniLeagues(id, true, type);
    }

    //api/Leagues/GetMiniLeagueTable/3
    [GET("api/Leagues/GetMiniLeagueTable/{id}")]
    public List<SportTableRow> GetMiniLeagueTable([FromUri]int id)
    {
        return SportManager.GetMiniLeagueTable("", id).TableRows;
    }
}
Run Code Online (Sandbox Code Playgroud)

当我调用第一种方法时Get,这很好用.当我使用fiddler或Chrome REST Client调用第二种方法时GetMiniLeagueTable,我收到以下错误:

{消息:"请求无效." MessageDetail:"参数字典包含参数'type'的非可为空类型'CompetitionManager + MiniLeagueType'的空条目,方法'System.Collections.Generic.List`1 [竞争] Get(Int32,MiniLeagueType)''LeaguesController '.可选参数必须是引用类型,可以为空的类型,或者声明为可选参数." }

AttributeRouting用来装饰方法,但这似乎不起作用.在我介绍之前它工作正常MiniLeagueType.

有人遇到过这个问题,还是你能指出我哪里出错了?

c# asp.net-web-api attributerouting asp.net-web-api-routing

2
推荐指数
1
解决办法
2962
查看次数

Angular和RxJ结合了两个http请求

我正在执行两个http请求,每个请求都返回a observable<IProduct>;,我想将两者都组合到一个本地对象中,并使用异步管道从每个请求中获取值。

productA$: observable<IProduct>;
productB$: observable<IProduct>;
combinedProds$: ?

this.productA$ = httpCall();
this.productB$ = httpCall();


  this.combinedProds$ = combineLatest([
  this.productA$,
  this.productB$
   ])
  .pipe(
    map(([productA, productB]) =>
      ({ productA, productB}))
  );
Run Code Online (Sandbox Code Playgroud)

我遇到的这个问题,我不知道combinedProds$应该是哪种类型。

javascript rxjs typescript angular

2
推荐指数
1
解决办法
53
查看次数

手动更新DB时,使用SignalR和Knockout更新UI

我为此搜索了SO,但没有遇到任何明显的问题.我有一个工作仪表板,它们的状态在一天中不断变化,我正在尝试将一些概念证明应用程序放在一起,并通过在数据库中运行更新命令来手动触发更新.这就是我设置的,但是当我执行更新时,我看不到UI的任何变化,你能看到我哪里出错吗?

毂:

public class DashboardHub : Hub
{
    private readonly Repository _repository;

    public DashboardHub()
    {
        _repository= new Repository();
    }

    public void GetJobs()
     {
         var jobs =  _repository.GetJobs();

        Clients.All.allJobsRetrieved(jobs);
     }
}
Run Code Online (Sandbox Code Playgroud)

淘汰视图模型

$(function () {
    $(function () {
        function jobViewModel(id, name, isPaused, currentStatus, cob, owner) {
            this.hub = $.connection.dashboardHub;

            //job variables, initialised from params
            this.Id = id;
            this.Name = ko.observable(name);
            this.IsPaused = ko.observable(isPaused);
            this.CurrentStatus = ko.observable(currentStatus);
            this.Cob = ko.observable(cob);
        }

        function dashboardViewModel() {
            this.hub = $.connection.dashboardHub;

            //jobs collection
            this.jobs = ko.observableArray([]); …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc signalr knockout.js

1
推荐指数
1
解决办法
2081
查看次数

ASP NET会话抛出.ToString()错误

我在IE9中的项目ASp.NEt c#中使用Session有问题.有时会出现错误:"对象引用未设置为对象的实例"

其他问题是在IE9中,有时候不会保存我的Session以将Idiom更改为其他页面.在Chrome中一切都很好!

错误

在此输入图像描述

下面是我的Page_Load和CarregaGrid().此问题有时发生,没有时间发生,并且在任何页面中都没有出现在所有页面中或只出现在一个特定页面中.

    public void CarregaGrid()
{
    var listByGroupM = new ManageUsers().ConsultUsersGroupM();
    if (listByGroupM != null)
    {
        this.GridView1.DataSource = listByGroupM;
        if (listByGroupM.Count != 0)
        {
            this.GridView1.DataBind();
            GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;
        }
    }

    if (divModify.Visible == true)
    {
        foreach (GridViewRow row in GridView1.Rows)
        {
            string idioma = CultureInfo.CurrentCulture.TwoLetterISOLanguageName.ToString();

            if (Session["idioma"].ToString() != null)
            {
                idioma = Session["idioma"].ToString();
            }

            Idioma.MudaCultura(idioma);

            Button btnDelete = (Button)row.FindControl("btnDelete");
            btnDelete.Text = Idioma.RetornaMensagem("btnDelete");

            string UserName = row.Cells[1].Text;
            PrincipalContext insPrincipalContext = new PrincipalContext(ContextType.Domain, "x.com", "x", "xxx");
            UserPrincipal insUserPrincipal = UserPrincipal.FindByIdentity(insPrincipalContext, …
Run Code Online (Sandbox Code Playgroud)

.net c# asp.net webforms

1
推荐指数
1
解决办法
2207
查看次数

MVC 4中数据库方法的最佳实践

我对MVC 4很陌生,到目前为止我在C#中主要使用Web表单.我理解MVC的模式,路由,调用动作等等.

但是负责从数据库中获取数据的操作呢,例如通过激活存储过程?我看过一些教程,他们在操作中直接连接数据库的逻辑.

但是,我正在考虑采用更集中的方式来实现它.例如,我可以将所有触发存储过程的函数放在一个名为DatabaseCoordinator.cs的单独类中,例如,名为Helpers的文件夹中.然后我可以从控制器中的动作调用它们.

通过这种方式,我将知道我可以在一个类中找到我的所有数据库方法,这是一个非常干净的解决方案,我认为(或至少在Web表单中).但是我想遵循MVC的模式,并且只使用模型,视图和控制器作为模式本身的名称.

那么最佳做法是什么?我应该为此单独创建一个类,还是直接在控制器中或者在其他地方实现逻辑?

c# data-access-layer asp.net-mvc-4 .net-4.5

1
推荐指数
2
解决办法
1万
查看次数

SQLSTATE [42601]:语法错误:7

我在PostgreSQL插入请求中有一些想法是不正确的.当我执行:

INSERT  INTO data
        ( Email ,
          Email_MD5 ,
          Date_In ,
          Tel_mobile ,
          Tel_fixe ,
          Gender ,
          Title ,
          FirstName ,
          LastName ,
          DateOfBirth ,
          YearOfBirth ,
          AgeGroupe ,
          Adresse_1 ,
          Adresse_2 ,
          CP ,
          Ville ,
          Domain ,
          Groupe_Domaine ,
          Last_Date_R ,
          Last_Date_O ,
          Last_Date_C ,
          Pression ,
          Activity ,
          R
        )
VALUES  ( "000090@voila.fr" ,
          "b6ffc0c54f2c35866c4ccc4a7218472c" ,
          NULL ,
          "" ,
          "5789332" ,
          "MLLE" ,
          "" ,
          "Lydia" ,
          "Le Port" ,
          NULL ,
          NULL ,
          "26 - …
Run Code Online (Sandbox Code Playgroud)

sql postgresql

1
推荐指数
1
解决办法
7392
查看次数

TypeError:无法读取未定义的属性"getAccounts"

我正在关注John Papa的Angular Style指南来创建一个小应用程序,我似乎无法解决controller使用a service...中的方法的问题.

(function () {
    'use strict';
    var accountsApp = angular.module('accountsApp', ['ui.bootstrap', 'ngAnimate']);
})();
Run Code Online (Sandbox Code Playgroud)

调节器

(function() {
    'use strict';

    angular
        .module('accountsApp')
        .controller('accountsCtrl', accountsCtrl);

    accountsCtrl.$inject = ['$log'];

    function accountsCtrl($log, accountsDataSvc) {
        /* jshint validthis:true */
        var vm = this;
        vm.title = 'Accounts';
        vm.accounts = [];
        vm.accountForm = null;
        vm.account = { id: 0, name: '', description: '' }

        activate();

        function activate() {
            return getAccounts(1).then(function() {
                $log.info('Accounts loaded');
            });
        }

        function getAccounts(id) {
            return accountsDataSvc.getAccounts(id).then(function(data) { …
Run Code Online (Sandbox Code Playgroud)

javascript dependency-injection iife angularjs

1
推荐指数
1
解决办法
301
查看次数

错误 TS5014:无法解析文件“tsconfig.json”:位置 57 处的意外令牌/JSON

我将我的打字稿项目移到了 win 7 计算机上。当 tsconfig 在我的 win 10 计算机上运行良好时,我收到此错误。我按照此处的建议删除了最后两个尾随逗号,但错误仍然存​​在。

我的 tsconfig:

{
  "compileOnSave": true,
  "compilerOptions": {
    /* Visit https://aka.ms/tsconfig.json to read more about this file */
    /* Basic Options */
    // "incremental": true,                   /* Enable incremental compilation */
    "target": "es5",                          /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
    "module": "commonjs",                     /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
    "strict": true,                           /* Enable …
Run Code Online (Sandbox Code Playgroud)

typescript tsconfig

1
推荐指数
1
解决办法
1865
查看次数

在会话中保存数组 C# 错误

我正在尝试在会话中保存数组并尝试将其恢复。以下是代码。但是当我调用 WebMethod 时出现以下错误。我正在使用c#。VS2010

错误:

System.NullReferenceException:未将对象引用设置为对象的实例。在 C:\Users\uydarp\Documents\Visual Studio 2010\Projects\xmlRW1\xmlRW1\Service1.asmx.cs 中的 xmlRW1.Service1.logic() 处:第 86 行

[WebMethod]
    public int logic()
    {
        int[] myArray = { 1,2,3,4};
        Session["MyArray"] = myArray; 

        int[] myArray2 = (int[])Session["MyArray"];
        int firstElement = myArray2[0];

        return firstElement;
    }
Run Code Online (Sandbox Code Playgroud)

c# asp.net web-services

0
推荐指数
1
解决办法
98
查看次数

ASP.NET C#使用ClientScript.RegisterStartupScript传递参数

我有以下代码,应该在我的客户端脚本中调用一个名为ShowPopup的函数,但是有理由,当我调用此函数时没有任何反应.

  string pg = "Test";
  ClientScript.RegisterStartupScript(this.GetType(), "Popup", "ShowPopup(pg);", true);
Run Code Online (Sandbox Code Playgroud)

如果我执行以下操作:

ClientScript.RegisterStartupScript(
                   this.GetType(), "Popup", "ShowPopup('Test');", true);
Run Code Online (Sandbox Code Playgroud)

它工作正常.它确实出现在弹出窗口中.知道我可能做错了什么.

c# asp.net

0
推荐指数
1
解决办法
9929
查看次数