[英]Html.EditorFor additionalViewData
I have a custom editor template where I add values to the ViewData
like so: 我有一个自定义编辑器模板,我在其中向
ViewData
添加值,如下所示:
@Html.EditorFor( model => model.PhoneNumber , new { Title = "SomeValue" } )
How can I access both the value and the property name? 如何访问值和属性名称?
ViewData is a dictionary. ViewData是一本字典。
You can write ViewData["Title"]
, or you can loop through ViewData
(which is a collection of KeyValuePairs) or ViewData.Keys
. 您可以编写
ViewData["Title"]
,也可以遍历ViewData
(KeyValuePairs的集合)或ViewData.Keys
。
You can nest your htmlAttributes object in view data: 您可以在视图数据中嵌套htmlAttributes对象:
<%= Html.EditorFor(model => model.PhoneNumber, new { htmlAttributes = new { Title = "SomeValue" } })
Then in your editor template: 然后在您的编辑器模板中:
<%= Html.TextBox("", Model.Value, ViewData["htmlAttributes"])%>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.