Complex models and partial views - model binding issue in ASP.NET MVC 3

后端 未结 2 1075
耶瑟儿~
耶瑟儿~ 2020-11-28 22:39

I have 2 models in my sample MVC 3 application, SimpleModel and ComplexModel, shown below:

public class SimpleModel
{
    public st         


        
2条回答
  •  星月不相逢
    2020-11-28 23:00

    As Daniel Hall suggests in his blog, pass a ViewDataDictionary with a TemplateInfo where HtmlFieldPrefix is set to the name of the SimpleModel-property:

     @Html.Partial("_SimplePartial", Model.Simple, new ViewDataDictionary(ViewData)
        {
            TemplateInfo = new System.Web.Mvc.TemplateInfo
            {
                HtmlFieldPrefix = "Simple"
            }
        })
    

提交回复
热议问题