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
Instead of using Html.RenderPartial
you could use editor templates which will handle prefixes.
So in your main view:
<%-- See below what does the second argument mean --%>
<%= Html.EditorFor(x => x.RegisterModel, "RegisterModel") %>
<%= Html.EditorFor(x => x.LoginModel, "LoginModel") %>
And then create a folder Views/Shared/EditorTemplates/RegisterModel.ascx
(The name of this file is used in the EditorFor
helper method). Also notice that this partial should be strongly typed to the type of the RegisterModel
property:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<% using (Html.BeginForm("Register", "Member")) { %>
<% } %>
You could define a different partial for the login model in Views/Shared/EditorTemplates/LoginModel.ascx