ASP.Net MVC 2,0 EditorForModel问题

时间:2021-06-15 08:09:57

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:

我编写了一个Enum扩展方法,允许我创建一个视图模型,并允许我轻松地将通用枚举绑定到SelctList,如:

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.

注意我使用的是EditorForModel,然后是一个单独的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?

我的问题是:有没有办法让EditorForModel足够聪明地拿起我想要使用SelectList而不是TextBox的状态?

Many Thanks

非常感谢

Ted

摊晒

1 个解决方案

#1


1  

EditorForModel pays attention to a UIHint Attribute on your Properties. It will check if you have an Editor template for that UI Hint and try to use that for your form.

EditorForModel关注Properties的UIHint属性。它将检查您是否有该UI提示的编辑器模板,并尝试将其用于您的表单。

#1


1  

EditorForModel pays attention to a UIHint Attribute on your Properties. It will check if you have an Editor template for that UI Hint and try to use that for your form.

EditorForModel关注Properties的UIHint属性。它将检查您是否有该UI提示的编辑器模板,并尝试将其用于您的表单。