从数据注释Asp.Net的mvc隐藏域 [英] Asp.Net Mvc Hidden Field from Data Annotations
本文介绍了从数据注释Asp.Net的mvc隐藏域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我认为这将是对谷歌快速搜索,但也许我失去了一些东西。有没有一种方法,使用数据注释,设置一个视图模型属性创建HiddenInput当标记得到呈现?
I thought this would be a quick search on google but maybe I'm missing something. Is there a way, using Data Annotations, to set a ViewModel property to create a HiddenInput when the markup get rendered?
我发现的唯一的注释是完全隐藏视图中的财产,我还是希望物业渲染,但作为一个隐藏的输入。
The only annotations I've found were to hide the property from the view entirely, I still want the property rendered but as a hidden input.
推荐答案
此属性:
[System.Web.Mvc.HiddenInput(DisplayValue = false)]
public int Id { get; set; }
将呈现为即。
<input id="Id" name="Id" type="hidden" value="21" />
当使用
Html.EditorForModel()
或 Html.EditorFor(M = GT; m.Id)
这篇关于从数据注释Asp.Net的mvc隐藏域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文