我有一个像这样的模特
public class TestModel
{
public Person person{ get; set; }
public string Type { get; set; }
}
public class Person
{
public string FirstName{ get; set; }
public string LastName{ get; set; }
}
当我为Test模型创建一个视图时,生成的视图就像这样:
@using (Html.BeginForm()) {
<fieldset>
<legend>TestModel</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Type)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Type)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
如何更改为此类
生成Prson属性代码的模板 @using (Html.BeginForm()) {
<fieldset>
<legend>TestModel</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Type)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Type)
@Html.ValidationMessageFor(model => model.Type)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Person.FirstName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Person.FirstName)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Person.LastName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Person.LastName)
</div>
</fieldset>