在表单提交时传递整个模型 [英] Pass an entire model on form submission

查看:87
本文介绍了在表单提交时传递整个模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以使用@Html.HiddenFor(m => m.parameter),并且在提交表单时,该参数将传递给控制器​​.我的模型有很多属性.

I understand that I can use @Html.HiddenFor(m => m.parameter) and when the form is submitted, that parameter will be passed to the controller. My model has many properties.

是否有一种较短的方法可以一次将整个模型传递给控制器​​,还是必须每次都一次完成?

Is there a shorter way of passing the entire model at once to the controller or must I do it one by one each time?

推荐答案

该模型将全部传递给控制器​​,但不受输入或隐藏字段约束的属性值将丢失.

The model will be passed to the controller in its entirety, but the values of properties that are not bound by input or hidden fields will be lost.

您必须在客户端上以表单的形式绑定属性,或者在服务器端上重新获取实体.

You have to either bind the properties in the form on the client-side, or re-fetch the entity on the server-side.

您似乎在要求类似@Html.HiddenFor(m => m.Model)之类的东西,这是不可能的.抱歉

You seem to be asking for something like @Html.HiddenFor(m => m.Model), and that is not possible. Sorry

要记住的一件事是,如果您有大量的隐藏字段,则可能向视图发送的数据量超出了您的实际需要.考虑使用视图模型

One thing to keep in mind, if you have tons of hidden fields, you may be sending more data to the view than you really need. Consider employing view models

这篇关于在表单提交时传递整个模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆