Monday, 15 August 2011

ASP.NET MVC: How to create a model that will bind to this POSTed data? -



ASP.NET MVC: How to create a model that will bind to this POSTed data? -

i'm having problem creating model bind form info below . main difficulty i'm having creating model bind filter (ie: multi-dimensional array).

this have far. can help me model bind properly?

public class getpagedrequest { public int start { set; get; } public int limit { set; get; } public string dir { set; get; } public list<filterrequest> filter { set; get; } //this won't bind } public class filterrequest { public string field { set; get; } public datafilterrequest info { set; get; } } public class datafilterrequest { public string type { set; get; } public string value { set; get; } }

i not back upwards solution jherrera:

[httppost] public actionresult receivepostfromjson() { string jsonstringify = new system.io.streamreader(request.inputstream).readtoend(); var obj = new javascriptserializer().deserialize<getpagedrequest>(jsonstringify); homecoming view(obj); }

if want recieve json info client on server side should prepare client side object have save construction server side viewmodel. way model binder job when form submitted.

code not tested:

public actionresult deletexxx(getpagedrequest pagedrequestviewmodel) { // utilize automapper or ui service reshape/map viewmodel domain model homecoming emptyresult(); }

asp.net-mvc model

No comments:

Post a Comment