Sta*_*low 2 asp.net-mvc razor asp.net-core-mvc asp.net-core
似乎没有多少人在测试asp.net vNext MVC 6,因为我无法挖掘出太多资源.我很感兴趣,所以这些天我一直在测试它.
在Scott的文章中,他说
所以不要写这个:
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(m => m.UserName, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.UserName, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.UserName, "", new { @class = "text-danger" })
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
你可以写这个:
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="UserName" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="UserName" class="form-control" />
<span asp-validation-for="UserName" class="text-danger"></span>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我在运行Windows Server 2012和Visual Studio 2015 CTP的azure虚拟机中尝试过它.新的HTML标记没有用.我使用新语法对这些输入字段进行回发时获得空值,input asp-for
并且span asp-validation-for
也无法吐出我期望的验证消息.我找不到任何更新.我错过了任何使这个新标记失败的东西吗?谢谢.
确保在模型声明下方包含帮助程序库
@addtaghelper "Microsoft.AspNet.Mvc.TagHelpers"
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1133 次 |
最近记录: |