我正在尝试创建客户端验证。当我将页面上的字段保持为空并单击提交按钮时,服务器端验证正在运行,但客户端验证不起作用。我还在layout.cshtml文件中包含jqueryval
包。
@Scripts.Render("~/bundles/jqueryval")
我还检查了web.config文件中的以下行
<add key="ClientValidationEnabled" value="true" />
型号:
public class File
{
[Required]
public string Name { get; set; }
[Required]
public string Description { get; set; }
public DateTime DateCreated { get; set; }
public DateTime DateModified { get; set; }
[Required]
public string FileSrc { get; set; }
}
查看:
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>File</h4>
<hr />
@Html.ValidationSummary(false, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Description, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextAreaFor(model => model.Description, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Description, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.FileSrc, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<input type="file" id="FU" multiple />
@Html.HiddenFor(model => model.FileSrc,new { id="fm"})
@Html.ValidationMessageFor(model => model.FileSrc, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
AM我错过了什么?
答案 0 :(得分:-2)
附加jquery不显眼的脚本