我们如何将模型绑定到MVC 4中的列表?
Create a MVC Project, leave everything default and add Product in your Models folders with the following (very simple) code:
namespace BlogPost.Models
{
public class Product
{
public string Name { get; set; }
}
}
Then add a ProductsController (in the Controllers folder) with the following code:
using System.Collections.Generic;
using System.Web.Mvc;
using BlogPost.Models;
namespace BlogPost.Controllers
{
public class ProductsController : Controller
{
public ActionResult Add()
{
return this.View();
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Add(IList<Product> products)
{
return this.View();
}
}
}
Source: http://kristofmattei.be/2009/10/19/asp-net-mvc-model-binding-to-a-list/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.