[英]bind a model to list in asp.net mvc 4
我們如何將模型綁定到MVC 4中的列表?
創建一個MVC項目,將所有內容保留為默認值,並使用以下(非常簡單的)代碼將產品添加到您的Models文件夾中:
namespace BlogPost.Models
{
public class Product
{
public string Name { get; set; }
}
}
然后使用以下代碼添加一個ProductsController(在Controllers文件夾中):
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();
}
}
}
資料來源: http : //kristofmattei.be/2009/10/19/asp-net-mvc-model-binding-to-a-list/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.