Post JSON array to mvc controller

前端 未结 3 1125
遇见更好的自我
遇见更好的自我 2020-12-01 12:48

I\'m trying to post a JSON array to an MVC controller. But no matter what I try, everything is 0 or null.

I have this table that contains textboxes. I need from all

3条回答
  •  没有蜡笔的小新
    2020-12-01 13:03

    I think you doing thing's in a bit wrong manner for MVC world. If you have a proper model for binding your data with - you better using helpers going from the box instead of using "handmade" JavaScript. Take a look to HtmlHelper or AjaxHelper if you need async calls.

    And bind you data to model using @Html.TextBoxFor() notation inside @Html.BeginForm block That will simplify your code much and reduce amount of javascript, which is much better for maintenance.

    On the server part you need to implement custom model binder and change settings to make handle request for current controller action via your model binder. It will take you to write some serverside code, but statically typed code looks easier to code and test or me, and it's better suit or your application needs, because I prefer JavaScript doing things it should do = > managing UI, but not constructing model for correct parsing on the serverside. It's better suit for single responsibility principle.

    See this video, this is simple tutorial how to do that

提交回复
热议问题