本文主要实验如何应用AspNet Mvc内建功能(DefaultModelBinder)实现简单类型复杂类型集合类型以及字典类型的自动绑定 简单类型 这里我们将下面这个Book类称为简单类型 public class Book { public int BookId { get; set; } public string BookName { get; set; } public string Author { get; set; } public DateTime PublishedDate { get; set; } } 假设现在需要实现添加Book的功能那么在BookController中会定义如下的Action [AcceptVerbs(HttpVerbsPost)] public ActionResult Create(Book book) { //TO DO //Insert book into Database return RedirectToAction(Index); } 现在的问题便是在View中如何命名TextBox来达到自动绑定如下 <div> <%using (HtmlBeginForm(Create Book)) { %> <div> Book Name: <%=HtmlTextBox(BookName)%> </div> <div> Author: <%=HtmlTextBox(Author)%> </div> <div> Published Date: <%=HtmlTextBox(PublishedDate)%> </div> <div> <input type=submit id=submit name=submit value=submit > |