Asp.net MVC不显示模板编辑

发布于 2024-12-07 11:09:42 字数 1680 浏览 0 评论 0原文

我有课程:

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

共享文件夹> 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>

在我看来:

@Html.EditorForModel()

仅显示 UrlKeywordReCapcha 字段!

为什么 Asp.net MVC 不使用共享文件夹中的模板来显示我的嵌套类型 PersonDetailsModel

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不交电费瞎发啥光 2024-12-14 11:09:42

你知道,你可以刚刚编辑你的其他问题。 :)

无论如何,我认为这不会起作用。您要么需要自己控制整个模板,要么让 MVC 自己完成这一切。 (我可能是错的)

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)

或者您可以在 Groom 上使用 [UIHint("PersonDetailsModel"] 属性和 ViewModel 中的 Bride 属性

请阅读 EditorForModel 了解这一切是如何进行的作品。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文