J'ai le modèle suivantMVC 3 - Validation client de la liste
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; }
}
Contrôleur
public ActionResult Edit(int id)
{
return View(_db.Products.FirstOrDefault(p => p.id.Equals(id)).ProductLangs);
}
Voir
@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" />
}
J'ai J'ai vu les autres et le contrôleur où jquery fonctionne de manière discrète, mais pas ici. Je suppose parce que j'ai une liste. En fait, si j'ai fait une vue avec un seul objet, ça marche.
Comment lier jquery validation nonobstrusive à une liste?