ASP.NET MVC 中将FormCollection与实体间转换方法

      将Action动作中传递的FormCollection转变成对应的实体,可以使用Controller的TryUpdateModel()方法。
  1. public ActionResult Create(FormCollection collection)  
  2. {  
  3.     try  
  4.     {  
  5.         if (ModelState.IsValid)  
  6.         {  
  7.             var student = new Student();  
  8.             //在这里转换  
  9.             TryUpdateModel<Student>(student, collection);  
  10.             dalStudent.Add(student);  
  11.             return RedirectToAction("Index");  
  12.         }  
  13.         else  
  14.             return View();  
  15.     }  
  16.     catch  
  17.     {  
  18.         return View("Create");  
  19.     }  
原文地址:https://www.cnblogs.com/Roxlin/p/5629081.html