MVC 4 ViewModel not being sent back to Controller

后端 未结 9 1796
感情败类
感情败类 2020-12-08 07:17

I can\'t seem to figure out how to send back the entire ViewModel to the controller to the \'Validate and Save\' function.

Here is my controller:

[H         


        
9条回答
  •  清歌不尽
    2020-12-08 07:43

    This isn't MVC specific. The HTML form will only post values contained within form elements inside the form. Your example is neither inside the form or in a form element (such as hidden inputs). You have to do this since MVC doesn't rely on View State. Put hidden fields inside the form:

    @Html.HiddenFor(x => x.Transaction.Time)
    // etc...
    

    Ask yourself though.. if the user isn't updating these values.. does your action method require them?

提交回复
热议问题