你必须使用
EditorTemplate
和
EditorFor
helper将根据模板自动渲染模型,您无需依赖
htmlAttributes
DateTime
,
IFormFile
UserModelTemplate.cshtml:
-------------------------
@model UserModel
<div class="form-group">
<label class="hero-label">
@Html.DisplayNameFor(m=> m.Username)
<span class="text-danger">
@Html.ValidationMessageFor(m=> m.Username)
</span>
</label>
@Html.TextBoxFor(m=> m.Username, new { @class = "form-control"})
</div>
你可以继续这样下去。开发完模板后,可以将其与
编辑
助手(
将其放在共享文件夹中,也可以放在子文件夹中,以便更好地组织
)
@Html.EditorFor(model=> model, "UserModelTemplate")