0
我在與同的NuGet萬全包客戶端驗證的麻煩。MVC 5萬全客戶端驗證
我的模型
public class Item {
public int Id { get; set; }
[Required]
public double Quantity { get; set; }
[RequiredIfNotEmpty("Quantity")]
public string LocationCode { get; set; }
public IEnumerable<SelectListItem> LocationList { get; set; }
}
在我看來,我有
@model IList<MyApp.Models.Item>
<!-- some HTML -->
@for(int i = 0; i < Model.Count; i++)
{
<tr>
<td>
@Html.DropDownListFor(p => p[i].LocationCode, Model[i].LocationList, string.Empty, new { @class = "form-control" })
@Html.ValidationMessageFor(p => p[i].LocationCode)
</td>
<td>
@Html.TextBoxFor(p => p[i].Quantity, new { @class = "form-control"})
@Html.ValidationMessageFor(p => p[i].Quantity)
</td>
</tr>
}
在我_Layout.cshtml我有以下軟件包包括:
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@Scripts.Render("~/bundles/jqueryval")
@RenderSection("scripts", required: false)
而且我jqueryval包看起來像這樣的:
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.validate*",
//"~/Scripts/MvcFoolproofJQueryValidation.min.js",
"~/Scripts/mvcfoolproof.unobtrusive.min.js"
//"~/Scripts/MvcFoolproofValidation.min.js"
));
在我的web.config我有:
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
我已經嘗試不同的組合與mvcfoolproof js文件,但我根本無法獲得客戶端驗證工作。對於數量文本框它正在工作。請注意,服務器端IS正在工作。
不信任客戶端 –
@ThomasAndreèLian這就是爲什麼我也有服務器端驗證 – kwv84
您的[[RequiredIfNotEmpty(「Quantity」)]'屬性沒有意義。 'Quantity'是typeof'double',它永遠不會是'null',所以重要的是什麼? –