Featured post
asp.net mvc - two nested model properties of same complex type -
i have customer model 2 complex properties "internaladdress" , "publicaddress" both of same model type address.
in view doing following
<h2>internal address</h2> <% renderpartial("address", model.internaladdress);%> <h2>public address</h2> <% renderpartial("address", model.publicaddress);%>
it gets rendered without exceptions rendered html use same input-names both partialviews...
is there smart way handle situation?
it's you're combining functionality using partial views, since of time address rendered 1 way.
one way display form using mvc2 editorfor , displayfor templates. move partial view form /views/shared/editortemplates/address.ascx (and display-only portion if have 1 /views/shared/displaytemplates/address.ascx).
once that's done, can use 1 of 2 ways.
option 1:
you can edit viewmodel this:
[uihint("address")] public address internaladdress { get; set; } [uihint("address")] public address publicaddress{ get; set; }
the uihint tells templating engine use view called "address" in shared/editortemplates folder.
then can use editorfor template in view no modifications:
<%: html.editorfor(model => model.internaladdress) %>
option 2:
simply specify template's name in editorfor in view:
<%: html.editorfor(model => model.internaladdress, "address") %>
- Get link
- X
- Other Apps
Comments
Post a Comment