namespace MvcWebGrid.Models
{
public class Customer
{
public string CustomerCode { get; set; }
public string CustomerName { get; set; }
}
}
namespace MvcWebGrid.Controllers
{
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
List<Customer> Custs = new List<Customer>();
Custs.Add(new Customer{CustomerCode="1001",CustomerName="gan"});
Custs.Add(new Customer{CustomerCode="1002",CustomerName="ting"});
return View(Custs);
}
}
}
@model List<MvcWebGrid.Models.Customer>
@{
ViewBag.Title = "Index";
}
@{
var grid = new WebGrid(Model,
defaultSort:"CustomerCode",
canPage: true
);
<div id="DivGrid">
@grid.GetHtml(
columns:grid.Columns(
grid.Column("CustomerCode","Customer Code"),
grid.Column("CustomerName","Customer Name")
)
)
</div>
}