ASP.NET MVC 2 - ViewModel Prefix

前端 未结 4 1666
栀梦
栀梦 2021-02-13 21:45

I want to use RenderPartial twice in my view with different models associated. The problem is that some properties are present in both models (nickname, password). They have no

4条回答
  •  梦如初夏
    2021-02-13 22:05

    If you can't do an EditorTemplate for some reason, you can do this in your View:

    var dataDict = new ViewDataDictionary();
    dataDict.TemplateInfo.HtmlFieldPrefix = "myPrefixHere";
    Html.RenderPartial("myPartialViewName", myPartialViewModel, dataDict);
    

    Lo and behold, all inputs in your PartialView will be prefixed.

    Kudos to R0MANARMY for pointing this out.

提交回复
热议问题