gpt4 book ai didi

asp.net-mvc - 从 ASP.NET MVC 中的 ViewModel 中删除前缀

转载 作者:行者123 更新时间:2023-12-04 18:20:39 25 4
gpt4 key购买 nike

我有一个由几个嵌套类组成的 ViewModel 类:

 public class UserAccountViewModel : UserProfileViewModel
{
public UserAccountEmailViewModel UserAccountEmail { get; set; }
public UserAccountLocationViewModel UserAccountLocation { get; set; }
public UserAccountPasswordViewModel UserAccountPassword { get; set; }
}

由此呈现的 HTML(注意 model.UserAccountEmail.Email ):
<div class="editor-label">
@Html.LabelFor(model => model.UserAccountEmail.Email)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.UserAccountEmail.Email)
@Html.ValidationMessageFor(model => model.UserAccountEmail.Email)
</div>

这是:
name="UserAccountEmail.Email"

我希望名称简单地为 Email
更改 ViewData.TemplateInfo.HtmlFieldPrefix没有帮助。重载 htmlFieldName@Html.EditorFor不会起作用,因为我仍然希望标签和验证消息与呈现的 HTML 元素匹配(这些函数中的 htmlFieldName 没有重载)。

我宁愿不为此创建部分。

编辑:

嗯...使用部分实际上并不算太糟糕。这实际上很有意义。

最佳答案

在这里查看我关于这个设计的回答,这可能对这个特定的策略有意义

Many models to view with many partial views

关于asp.net-mvc - 从 ASP.NET MVC 中的 ViewModel 中删除前缀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10770326/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com