ナゲットのフールプルーフ パッケージを使用したクライアント側の検証に問題があります。
私のモデル
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 ファイルとさまざまな組み合わせを試しましたが、クライアント側の検証を機能させることができません。Quantity テキストボックスでは機能しています。サーバー側の IS が機能していることに注意してください。