zoukankan      html  css  js  c++  java
  • FormCollection的用法

    FormCollection的用法:

    有时候前台抛来的字段太多,在后台一个一个例举出来显得麻烦,而且还容易出错,FormCollection解决了这个烦恼

     #region 给商家留言
            [HttpPost]
            public ActionResult LeaveMessage(FormCollection fc)
            {
                bool result = false;
                UserShopMessage userShopMessage = new UserShopMessage() 
                {
                    UID=Net.ConvertHelper.ToInt(fc["uid"]),
                    ShopsID=Net.ConvertHelper.ToInt(fc["shopsid"]),
                    ProductName=fc["productName"],
                    ProductImageUrl=fc["productImage"],
                    PRID=Net.ConvertHelper.ToInt(fc["prid"]),
                    MessageType=0,
                    Message=fc["message"],
                    IsRead=0,
                    CreateTime=DateTime.Now
                };
                result = ProductList.Instance.AddLeaveMessage(userShopMessage);
                return Content(result ? "ok" : "error");
            }

     ====

    [HttpPost]  
    public ActionResult Create(FormCollection collection)  
    {  
        try  
        {  
            if (ModelState.IsValid)  
            {  
                var student = new Student();  
                //在这里转换  
                TryUpdateModel<Student>(student, collection);  
                dalStudent.Add(student);  
                return RedirectToAction("Index");  
            }  
            else  
                return View();  
        }  
        catch  
        {  
            return View("Create");  
        }  
    }  
  • 相关阅读:
    Win10创意者更新秋季版激活秘籍
    将刷了Android的Lumia恢复为WP系统
    给Lumia 520/521/525/526/720刷Android系统
    DNS解析
    遍历对象目录
    PE注入
    利用NtCreateThreadEx注入
    利用CreateRemoteThread注入
    APC注入
    SetWindowHookEx()注入
  • 原文地址:https://www.cnblogs.com/xbblogs/p/4858393.html
Copyright © 2011-2022 走看看