是否有某种方式使用@ Html.HiddenFor完整模式? [英] Is there some way to use @Html.HiddenFor for complete model?
问题描述
有没有办法使用(或东西simular)
Is there a way to use (or something simular)
@Html.HiddenFor
为您的整个模型。
for your whole model.
因此,与其做这样的事情:
So instead of doing something like this:
@Html.HiddenFor(model => Model.Person.Name)
@Html.HiddenFor(model => Model.Person.LastName)
@Html.HiddenFor(model => Model.Address.Street)
使用这样的事情(这个例子不工作)
use something like this (this example doesn't work)
@Html.HiddenFor(model => Model)
我已经寻找它的计算器和谷歌......但没有发现任何东西了。
I've already searched for it on stackoverflow and google...but haven't found anything about it.
我要坚持到未保存到数据库的不同型号的一些值,所以只使用Html.HiddenFor的ID是不是我的选择。
I need to hold on to some values for different models that aren't saved into db, so using only Html.HiddenFor the ID is not an option for me.
在此先感谢!
推荐答案
选择您想在一个隐藏的输入属性,并在模型中添加 HiddenInputAttribute
如下
Select the properties you want to be in a hidden input and add the HiddenInputAttribute
in your model as follows:
public class MyModel
{
[HiddenInput]
public int MyProperty { get; set; }
}
这篇关于是否有某种方式使用@ Html.HiddenFor完整模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!