简体   繁体   English

ASP.Net MVC 2.0:编辑器用于通过属性设置名称

[英]ASP.Net MVC 2.0: EditorFor setting name via attributes

Just wondering how do I mimic the following using attributes... 只是想知道如何使用属性模仿以下内容...

<%= Html.EditorFor(x => x.SportProgramIdList, "FormMultiSelectDropDownList", "SportProgramIds")%>

I know I can specify the template by using [UIHint("FormMultiSelectDropDownList")] but I am left with the problem with how to set the name... 我知道我可以使用[UIHint(“ FormMultiSelectDropDownList”)]来指定模板,但是我仍然面临如何设置名称的问题...

Cheers Anthony 干杯安东尼

I Guess you'll have to create your own CustomAttribute UINameAttribute . 我猜您必须创建自己的CustomAttribute UINameAttribute You could use the ModelMetadata to keep your attribute and then I'm not sure what would be the best way to get it, i guess you would have to overide the HtmlHelper.EditorFor Extension without the parameter and pass your attribute to the next. 您可以使用ModelMetadata保留您的属性,然后我不确定获取它的最佳方法是什么,我想您必须覆盖不带参数的HtmlHelper.EditorFor Extension并将属性传递给下一个。

I'm too lazy and to tired to try for a more complete answer. 我太懒惰,累了,无法尝试一个更完整的答案。

look at : 看着 :

Why You Don't Need ModelMetadata.Attributes 为什么不需要ModelMetadata.Attributes

ASP.NET MVC 2 Templates, Part 2: ModelMetadata ASP.NET MVC 2模板,第2部分:ModelMetadata

Use the objectAttributes argument 使用objectAttributes参数

<%= Html.EditorFor(x => x.SportProgramIdList, "FormMultiSelectDropDownList", new { id="SportProgramIds" }) %>>

you can use this to set any of the html input attributes 您可以使用它来设置任何html输入属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM