ASP.Net MVC 5 - 如何使用 html 辅助方法更改原始 html?
ASP.Net MVC 5 - how to change raw html with html helper methods?
我有以下 html 代码,我想将其更改为使用 html 辅助方法。
<div class="form-group col-sm-4 col-md-4 col-lg-4">
<label>Date of Birth</label>
<div class="input-group date" id="dtp">
<input name="Birthday" id="txtBirthday" class="form-control" onfocus="$(this).next().trigger('click')" onkeydown="event.preventDefault()" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
@Html.ValidationMessageFor(m => m.Birthday)
</div>
我想使用 html 辅助方法将上面的 html 代码更改为以下代码,但我不知道如何在下面的代码。
<div class="form-group col-sm-4 col-md-4 col-lg-4">
@Html.LabelFor(m => m.Birthday)
@Html.EditorFor(m => m.Birthday, new { @class = "form-control", id="txtBirthday" })
@Html.ValidationMessageFor(m => m.Birthday)
</div>
您可以将 onfocus 和 onkeydown 添加到您添加 @class = "form-control
的同一对象。如下图
@Html.EditorFor(m => m.Birthday, new { @class = "form-control", id="txtBirthday", onkeydown = "event.preventDefault()", onfocus = "$(this).next().trigger('click')" })
我有以下 html 代码,我想将其更改为使用 html 辅助方法。
<div class="form-group col-sm-4 col-md-4 col-lg-4">
<label>Date of Birth</label>
<div class="input-group date" id="dtp">
<input name="Birthday" id="txtBirthday" class="form-control" onfocus="$(this).next().trigger('click')" onkeydown="event.preventDefault()" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
@Html.ValidationMessageFor(m => m.Birthday)
</div>
我想使用 html 辅助方法将上面的 html 代码更改为以下代码,但我不知道如何在下面的代码。
<div class="form-group col-sm-4 col-md-4 col-lg-4">
@Html.LabelFor(m => m.Birthday)
@Html.EditorFor(m => m.Birthday, new { @class = "form-control", id="txtBirthday" })
@Html.ValidationMessageFor(m => m.Birthday)
</div>
您可以将 onfocus 和 onkeydown 添加到您添加 @class = "form-control
的同一对象。如下图
@Html.EditorFor(m => m.Birthday, new { @class = "form-control", id="txtBirthday", onkeydown = "event.preventDefault()", onfocus = "$(this).next().trigger('click')" })