zoukankan      html  css  js  c++  java
  • 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.     }  
  • 相关阅读:
    下拉框插件开发 (一)
    工厂模式 抽象工厂模式
    闭包 构建函数 简单工厂模式
    js继承
    浅谈js观察者模式
    浅谈js单例模式
    localstorage本地存储
    Vi 配置文件
    Vi Command
    我的Firs博客
  • 原文地址:https://www.cnblogs.com/Roxlin/p/5629081.html
Copyright © 2011-2022 走看看