ASP.Net MVC 2,0 EditorForModel Question


ASP.Net MVC 2,0 EditorForModel Question



I have written an Enum extension method that allows me to create a view model and allows me to easily bind a generic Enum to a SelctList like:

this.ProductStatusList = new ProductStatusTypes().BindToSelectList<ProductStatusTypes>   (product.Status.ToString()); 

In my View I can then have:

<% using (Html.BeginForm()) {%>                    <fieldset>         <legend>Fields</legend>          <%= Html.EditorForModel() %>                           <%=Html.DropDownListFor(p => p.ProductStatusList, new                                  SelectList(Model.ProductStatusList, "Value", "Text",                                    Model.Status.ToString()))%>                        <p>             <input type="submit" value="Create" />         </p>     </fieldset> <% } %> 

Notice I am using EditorForModel and then a seperate DropDownList.

My question is: Is there a way to get the EditorForModel to be clever enough to pick up that I want to use a SelectList instead of a TextBox for status?

Many Thanks

Ted


How to make a default editor template for enums?

1:

Asp.net MVC Visible/hide
EditorForModel pays attention to a UIHint Attrialthough e on your Properties. AppFabric vs Unity vs Memcached or possibly any other multi server caching mechanisms [closed]It will check if you have an Editor template for this UI Hint and try to use this for your form.. ASP.NET MVC/LINQ - retreiving tables and number of connections
Is it better to return the most specific or most general type from an action method?

69 out of 100 based on 74 user ratings 229 reviews

#