MVC.NET array binding on the fly

On a Scotts post blog, he describes how to host an array of objects in a controller.

My question is , what is the best way to create a view for this that allows the user to add more array elements on the fly?

If i write

 foreach(MyModel item in Model)
 {
     <p>@Html.TextBoxFor(m => item.Name)</p>
 }

and let the controller add a new element to the array every time it generates <input type="text" name="item.Name" />without 1 Array index.

If I pass the code <input>then it works, but I lose all client-side validation attributes, such asdata-val-required="Name is required"

What I want to do is get the user to add new elements to the array on the fly and still keep the unobtrusive check? What is the best practice for this?

, , jQuery, , ?

, Tassadaque - .NET-, , -, . Muhammad Adeel Zahi , .

, HTML- jQuery live validation plug-in. - .

+5
2

This steve ,

+4

foreach, .

for(int i=0;i<Model.Count(); i++)
{
   <%:Html.TextBox("Items["+i+"].Name", Model[i].Name)%>
}

, , . , javascript, .

EDIT: blogged asp.net mvc jquery ,

+1

All Articles