I have the classes:
public class PersonDetailsModel
{
public string FistName
{
get;
set;
}
public string LastName
{
get;
set;
}
public string Email
{
get;
set;
}
}
public class RegisterCoupleModel
{
public PersonDetailsModel Groom
{
get;
set;
}
public PersonDetailsModel Bride
{
get;
set;
}
public string UrlKeyword
{
get;
set;
}
public string ReCaptcha
{
get;
set;
}
}
folder Shared > EditorTemplates
PersonDetailsModel.cshtml
@model BindSolution.AndMarried.ViewModel.PersonDetailsModel
<div class="editor-label">
@Html.LabelFor(m => m.FistName)
</div>
<div class="editor-field">
@Html.EditorFor(m => m.FistName)
@Html.ValidationMessageFor(m => m.FistName)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.LastName)
</div>
<div class="editor-field">
@Html.EditorFor(m => m.LastName)
@Html.ValidationMessageFor(m => m.LastName)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.Email)
</div>
<div class="editor-field">
@Html.EditorFor(m => m.Email)
@Html.ValidationMessageFor(m => m.Email)
</div>
In my View:
@Html.EditorForModel()
Only the UrlKeyword
and ReCapcha
fields are displayed!
Why Asp.net MVC not use templantes in shared folder to display my nested type PersonDetailsModel
?
You know, you could have just edited your other question. :)
Anyway, i don't think that will work. You either need to control the entire template yourself, or let MVC do it all itself. (i could be wrong)
Create an editor template for RegisterCoupleModel
:
@model BindSolution.AndMarried.ViewModel.RegisterCoupleModel
@Html.EditorFor(model => model.Groom)
@Html.EditorFor(model => model.Bride)
@Html.EditorFor(model => model.UrlKeyword)
@Html.EditorFor(model => model.ReCapcha)
Or you could use a [UIHint("PersonDetailsModel"]
attribute on your Groom
and Bride
properties in your ViewModel.
Read up on the remarks section in EditorForModel for how this all works.