ASP.MVC 3 Razor Add Model Prefix in the Html.PartialView extension

后端 未结 4 1828
野性不改
野性不改 2020-12-11 04:13

I have all most the same question as him ASP.NET MVC partial views: input name prefixes

I am tring to create CRUD operations for this data entities:

         


        
4条回答
  •  甜味超标
    2020-12-11 04:27

    As it turns out EditorTemplates is the way to go. (first comment on this post: http://thatextramile.be/blog/2011/01/prefixing-input-elements-of-partial-views-with-asp-net-mvc)

    Simply add ZipCodeViewModel.cshtml to an EditorTemplates folder, which can sit inside Views/Shared if you want. Then use, @Html.EditorFor(m => m.ZipCode). Works like magic.

提交回复
热议问题