我正在尝试在asp.net核心MVC项目中使用EditorTemplate,但它不起作用。
模型类示例:
[UIHint("YesNo")]
public int Status { get; set; }
共享文件夹中的My EditorTemplates文件夹。这就是YesNo.cshtml。
如果可能,请一步一步地分享。
发布于 2021-03-16 02:47:05
您可以按照以下步骤操作:
public类状态{ UIHint("YesNo") public int MyViewModel { get;set;} }
@model MyViewModel @Html.EditorFor(x => x.Status)
HttpGet公共IActionResult索引(){ var oVm =新MyViewModel { Status=5 };返回视图(OVm);}
Views/Shared
文件夹中创建EditorTemplates
文件夹。在EditorTemplates
中创建
YesNo.cshtml
Note:Remember表示您的UIHint
属性声明的属性类型为integer,因此分部视图(YesNo.cshtml
)允许使用integer类型:
@model int //must be int
<h2>Display YesNo.cshtml</h2>
@Html.Label("Status", Model.ToString())
@Html.Editor("Status")
结果:
https://stackoverflow.com/questions/66644022
复制相似问题