从MVC视图模型访问displayName属性 [英] Access displayName attribute from the model in MVC View
本文介绍了从MVC视图模型访问displayName属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我的模型有
[DisplayName的(名)]
公共字符串的firstName {搞定;组; }
然后我可以在LabelFor查看打印
@ Html.LabelFor(型号=> model.acc_first)
然后它会呈现为
<标签=名字>首先名称和LT; /标签>
- 但是,我怎么能生读属性(名字)在视图属性?
例如,如果我想的值发送到功能视图页面上
解决方案
@ Html.DisplayNameFor(X => x.acc_first)
If my model have
[DisplayName("First Name")]
public string firstName { get; set; }
Then I can print it in the View with LabelFor
@Html.LabelFor(model => model.acc_first)
It will then render as
<label for="firstName">First Name</label>
- But how can I "raw" read the property (FirstName) attributes in the View? If for example, I want to send the value to a function on the View page
解决方案
@Html.DisplayNameFor(x => x.acc_first)
这篇关于从MVC视图模型访问displayName属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文