Custom ViewModel with MVC 2 Strongly Typed HTML Helpers return null object on Create?

后端 未结 3 1758
清酒与你
清酒与你 2021-01-06 10:52

I am having a trouble while trying to create an entity with a custom view modeled create form. Below is my custom view model for Category Creation form.

publ         


        
3条回答
  •  误落风尘
    2021-01-06 11:38

    You could use editor templates. Put your ascx control in ~/Views/Shared/EditorTemplates/SomeControl.ascx. Then inside your main View (aspx page) include the template like so (assuming your view is strongly typed to CategoryFormViewModel):

    <%= Html.EditorForModel("SomeControl") %>
    

    instead of

    <% Html.RenderPartial("SomeControl", Model) %>
    

提交回复
热议问题