English 中文(简体)
2. 从请求后获得数据,以备p.net mvc
原标题:Get data since a request ajax with asp.net mvc

我要把所有数据输入一个有请求的物体。

This data are get into my controller with a function. In the headers of my data I have this information:

I have 4 objects allPly create but all data(gramme,lotion and others) equals null or zero. But the data comment and OtherData it s ok, this works.

感谢您的帮助

我请求:

var params={};
var allStep21 ={allData..}
$.extend(params,allStep21);
 $.ajax({
    type: "POST",
    url: "Request",
    data: params,
});

In the headers html:

allPly[0][Gramme]:10
allPly[0][Toto]:White
allPly[0][Test]:None
allPly[0][Lotion]:1
allPly[1][Grammage]:11
allPly[1][Toto]:White
allPly[1][Test]:Fine
allPly[1][Lotion]:0
OtherData : 585
Comment: all it s ok

在我的控制员中:

[HttpPost]
public ActionResult Request(AllStep21 allStep21)
{
}

In my model:

public class AllStep21
{
    public String OtherData { get; set; }
    public String Comment { get; set; }
    public List<allPly> allPly { get; set; }
}
public class allPly
{
    public int Gramme { get; set; }
    public String Toto { get; set; }
    public String Test { get; set; }
    public int Lotion { get; set; }
}
最佳回答

您可使用“智者”请求,允许你将任意复杂的物体送交你的控制者行动:

var params = { 
    allStep21: { 
        comment:  some comment , 
        otherData:  some other data ,
        allPly: [
            { toto:  toto 1 , test:  test 1 , lotion: 1, gramme: 1 },
            { toto:  toto 2 , test:  test 2 , lotion: 2, gramme: 2 }
        ]
    } 
};

$.ajax({
    url:  Request ,
    type:  POST ,
    contentType:  application/json; charset=utf-8 ,
    data: JSON.stringify(params),
    success: function(result) {
        alert( successs );
    }
});

The JSON.stringification methods listed here is homely established into all modern browsers. 但是,如果你需要支持遗留的浏览器,则需要列入json2.js

问题回答




相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...

热门标签