MVC 4 ViewModel not being sent back to Controller

后端 未结 9 1759
感情败类
感情败类 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:46

    The signature of the Send method that the form is posting to has a parameter named transaction, which seems to be confusing the model binder. Change the name of the parameter to be something not matching the name of a property on your model:

    [HttpPost]
    public ActionResult Send(BitcoinTransactionViewModel model)
    {
    }
    

    Also, remove the htmlAttributes parameter from your BeginForm call, since that's not doing anything useful. It becomes:

    @using (Html.BeginForm("Send", "DepositDetails", FormMethod.Post))
    

    Any data coming back from the client could have been tampered with, so you should only post back the unique ID of the transaction and then retrieve any additional information about it from your data source to perform further processing. You'll also want to verify here that the user posting the data has access to the specified transaction ID since that could've been tampered with as well.

提交回复
热议问题