这是在 Web 表单中使用具有相同属性的相同输入字段的情况下发生的。就像单个视图/页面中的登录和注册表单的情况一样。以前是这样的
输入一个 >
<div class="field-wrap">
@Html.TextBoxFor(model => model.Username, new { @class = "form-control",placeholder = "Username", @required = "required", autofocus = "" })
@Html.ValidationMessageFor(model => model.Username, "", new { @class = "text-danger" })
</div>
输入二>
<div class="field-wrap">
@Html.TextBoxFor(model => model.Username, new { @class = "form-control", placeholder = "Username", @required = "required", autofocus = "" })
@Html.ValidationMessageFor(model => model.Username, "", new { @class = "text-danger" })
</div>
然后我为用户名输入添加了一个唯一的 id #
新输入一个 >
<div class="field-wrap">
@Html.TextBoxFor(model => model.Username, new { @class = "form-control", id = "loginUsername", placeholder = "Username", @required = "required", autofocus = "" })
@Html.ValidationMessageFor(model => model.Username, "", new { @class = "text-danger" })
</div>
新输入二 >
<div class="field-wrap">
@Html.TextBoxFor(model => model.Username, new { @class = "form-control", id = "SignupUsername" , placeholder = "Username", @required = "required", autofocus = "" })
@Html.ValidationMessageFor(model => model.Username, "", new { @class = "text-danger" })
</div>