【发布时间】:2026-01-01 13:50:01
【问题描述】:
当我在 Razor 模板的顶部设置 ViewBag.Title 时,Model.Title 编辑器模板文本框将使用 ViewBag.Title 的值而不是预期的 Model.Title 值填充。显式调用 Html.EditorFor(x => Model.Title) 不会产生这种行为。
如何防止我的编辑器模板显示 ViewBag.Title 值而不为我的模型维护自定义编辑器模板?
代码
@{
ViewBag.Title = "Edit Post " + Model.Title;
}
@Html.EditorFor(x => Model.Title) @* renders "My Title" text box *@
@Html.EditorFor(x => Model) @* renders "Edit Post My Title" text box *@
【问题讨论】:
标签: asp.net-mvc viewbag mvc-editor-templates editorformodel