0

我有一个这样的模型

 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; }
}

当我为测试模型创建视图时,生成的视图如下所示:

@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>
4

0 回答 0