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