I have the following Model
public class ProductLang { public int productID { get; set; } public int langID { get; set; } [Required, StringLength(150)] public string name { get; set; } [AllowHtml] public string description { get; set; } }
controller
public ActionResult Edit(int id) { return View(_db.Products.FirstOrDefault(p => p.id.Equals(id)).ProductLangs); }
View
@model IEnumerable<ProductLang> @using (Html.BeginForm()) { @Html.ValidationSummary(true) @Html.Hidden("id", Model.FirstOrDefault().productID) @foreach (var productLang in Model) { <div> @Html.Hidden("prodLang.Index", productLang.idLingua) @Html.Hidden("prodLang[" + productLang.langID + "].productID", productLang.productID) @Html.Hidden("prodLang[" + productLang.langID + "].langID", productLang.langID) <div class="editor-label"> @Html.Label("prodLang" + productLang.langID + "__nome", "Name") </div> <div class="editor-field"> @Html.TextBox("prodLang[" + productLang.langID + "].name", productLang.name) @Html.ValidationMessage("prodLang[" + productLang.langID + "].name") </div> <div class="editor-label"> @Html.Label("prodLang" + productLang.langID + "__description", "Description") </div> <div class="editor-field"> @Html.TextArea("prodLang[" + productLang.langID + "].description", productLang.description) </div> </div> } <input type="submit" value="EDIT" /> }
I have other views and a controller where jquery unobstrusive validation works, but not here. I guess because I have a List. In fact, if I pretended with only one object, it works.
How to link jquery to unobtrusive list validation?
source share