asp.net mvc 3 - MVC 3 does not render editor template for object -


I have an MVC 3 application, which should allow the user to display and edit different types of values. Responsible for doing this is definitely not known about the type of value (it has been declared as an object), but I want to provide it the correct editor template. I have it right now:

  & lt;%: HTML.EditorFor (n = & gt; attribute value type)% & gt;   

Specialty. Value type is of type object when ValueTyped type is Bull, MVC returns a check box (which should have been done). However, as soon as ValueTyped is a different type (so far I've tried int, double, string), MVC does not render anything at all.

How do I make MVC common templates in int, double, string or whatever is included in my ValueTyped? Please note: I do not want to generate a text box myself, but I asked MVVC to decide which editor template should be used.

You can try to pass the name of editor editor clearly as a second argument and pass it Are there. Depending on your dynamic condition, it may look like the following:

  <: HTML.EditorFor (m = & gt; attr.ValueTyped, attr.ValueTyped.GetType (). Name)% & gt;   

Of course, your question is quite old - maybe you can update with the answer?

Comments