2

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...

Cheers Anthony

2 Answers 2

0

I Guess you'll have to create your own 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.

I'm too lazy and to tired to try for a more complete answer.

look at :

Why You Don't Need ModelMetadata.Attributes

ASP.NET MVC 2 Templates, Part 2: ModelMetadata

Sign up to request clarification or add additional context in comments.

Comments

-1

Use the objectAttributes argument

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

you can use this to set any of the html input attributes

1 Comment

This convention doesn't work for EditorFor or DisplayFor because you aren't passing in an anonymous HTML attributes object, it is an anonymous ViewData additions object. Adding something here would still require consuming it on a custom editor/display template. An example of this was done in an answer to a similar question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.