ASP.net MVC查看脚手架T4模板是否支持复杂属性?

时间:2013-06-19 09:45:53

标签: asp.net-mvc asp.net-mvc-4 t4

我有一个像这样的模特

 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>

0 个答案:

没有答案