English 中文(简体)
未经控制人员收监
原标题:Passed JSON collection not picked up by controller

我有以下小script:

$.ajax({
            url: self.LoadCirculationListUrl,
            cache: false,
            async: false,
            dataType:  json ,
            contentType:  application/json; charset=utf-8 ,
            data: [ { "ColumnName":"France","Comparitor":"=","Value":"1"},{"ColumnName":"Germany","Comparitor":">","Value":"3"}] 
        });

The controllre which is available from the above ajax calls:

public ActionResult LoadCirculationData(IList<CirculationListFilter> filters)
{
}

页: 1

public sealed class CirculationListFilter
{
    public string ColumnName { get; set; }

    public string Comparitor { get; set; }

    public string Value { get; set; }
}

现在,当我管理该守则时,控制人员没有把初等人物的藏书交给它;<编码>过滤器<>/代码>永远无效。 然而,如果我这样做的话:

$.ajax({
            url: self.LoadCirculationListUrl,
            cache: false,
            async: false,
            dataType:  json ,
            contentType:  application/json; charset=utf-8 ,
            data: { "ColumnName":"Germany","Comparitor":">","Value":"3"}
        });

主计长也这样做:

public ActionResult LoadCirculationData(CirculationListFilter filters)
{
}

这些数据经过了罚款。 为什么控制者会约束一批名人物品?

EDIT:

我改变了日本宇宙航空研究开发机构的呼吁:

data: { filters: [{ "ColumnName": "France", "Comparitor": "=", "Value": "1" }, { "ColumnName": "Germany", "Comparitor": ">", "Value": "3" }]},

* E/CN.6/2009/1。

public ActionResult LoadCirculationData(List<CirculationListFilter> filters)

现在filters有2个内项,但每一类“环发编码”栏目都含有联合国空间法研究所的财产数据。 因此,我更接近,但实际价值并没有受到约束。

最佳回答

问题在于:

.ajax () don t 换算数据为JSON string。

之所以为一个项目工作,是因为Jajax()能够将数据转换成MVC习惯接受的圈子。

解决办法是首先将“智者”改为“扼杀”:

$.ajax({
            url: self.LoadCirculationListUrl,
            cache: false,
            async: false,
            dataType:  json ,
            contentType:  application/json; charset=utf-8 ,
            data: JSON.stringify([ { "ColumnName":"France","Comparitor":"=","Value":"1"},{"ColumnName":"Germany","Comparitor":">","Value":"3"}]) 
        });
问题回答

我找到了另一种解决办法:

Ajax打电话:

data: {  json :  [{ "ColumnName": "France", "Comparitor": "=", "Value": "1" }, { "ColumnName": "Germany", "Comparitor": ">", "Value": "3" }]  },

主计长:

public ActionResult LoadCirculationData(string json)
{
    JavaScriptSerializer js = new JavaScriptSerializer();

    var obj = js.Deserialize<List<CirculationListFilter>>(json);
}

以上是我需要的。 确实不能确定为什么要由JSON约束的人不这样做。

如果你希望以这种形式重新计算

public ActionResult LoadCirculationData(IList<CirculationListFilter> filters)
{
}

你们需要用下一个格式数据公布: 页: 1

{
"ColumnName[0]":"Germany","Comparitor[0]":">","Value[0]":"3",
"ColumnName[1]":"Germany","Comparitor[1]":">","Value[1]":"3",
"ColumnName[2]":"Germany","Comparitor[2]":">","Value[2]":"3",
"ColumnName[3]":"Germany","Comparitor[3]":">","Value[3]":"3",
"ColumnName[4]":"Germany","Comparitor[4]":">","Value[4]":"3",
}




相关问题
WebForms and ASP.NET MVC co-existence

I am trying to make a WebForms project and ASP.NET MVC per this question. One of the things I ve done to make that happen is that I added a namespaces node to the WebForms web.config: <pages ...

Post back complex object from client side

I m using ASP.NET MVC and Entity Framework. I m going to pass a complex entity to the client side and allow the user to modify it, and post it back to the controller. But I don t know how to do that ...

Create an incremental placeholder in NHaml

What I want to reach is a way to add a script and style placeholder in my master. They will include my initial site.css and jquery.js files. Each haml page or partial can then add their own required ...

asp.net mvc automapper parsing

let s say we have something like this public class Person { public string Name {get; set;} public Country Country {get; set;} } public class PersonViewModel { public Person Person {get; ...

structureMap mocks stub help

I have an BLL that does validation on user input then inserts a parent(PorEO) and then inserts children(PorBoxEO). So there are two calls to the same InsertJCDC. One like this=>InsertJCDC(fakePor)...

ASP.NET MVC: How should it work with subversion?

So, I have an asp.net mvc app that is being worked on by multiple developers in differing capacities. This is our first time working on a mvc app and my first time working with .NET. Our app does not ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

热门标签