ASP.NET MVC 2 - ViewModel Prefix

前端 未结 4 1689
栀梦
栀梦 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:07

    First of all, you could use Html.TextBox("input form name", ...) and set the name to whatever you wish. There's a bigger issue how would you provide a prefix on Html.RenderPartial() level? You are already providing a model instance. So without changing their view models, there's just one more possibility: to write your own overloads for RenderPartial() that would take the prefix and pass it on to others.

    Check this one out. Someone's written a whole bunch of overloads that support setting prefixes. TextBoxFor rendering to HTML with prefix on the ID attribute

    If any is missing you can see the pattern how to extend these with additional ones you may need.

提交回复
热议问题