zoukankan      html  css  js  c++  java
  • request参数集合绑定实体实现defaultmodebinder

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using System.Reflection;
    namespace RequestParameter1.Controllers
    {
    
        public class Search {
    
            public string id { get; set; }
            public string name { get; set; }
        }
        public class HomeController : Controller
        {
            public ActionResult Index()
            {
                Type Mytype = typeof(Search);
              
                string[] arr = Request.QueryString.AllKeys;
                Search sear=new Search();
                foreach(string key in arr)
                {
                  Response.Write(string.Format("{0}={1}</br>",key,Request[key]));
                  PropertyInfo myproperinfo = Mytype.GetProperty(key);
                  if (myproperinfo != null)
                  {
                      myproperinfo.SetValue(sear, Request[key]);
                  }
                }
    
                return Json(sear,JsonRequestBehavior.AllowGet);
                return View();
            }
    
            public ActionResult About()
            {
                ViewBag.Message = "Your application description page.";
    
                return View();
            }
    
            public ActionResult Contact()
            {
                ViewBag.Message = "Your contact page.";
    
                return View();
            }
        }
    }
  • 相关阅读:
    Git 上传本地项目
    virtual和override
    ASP .NET依赖注入理解
    dotnet不是内部或外部的命令,也不是可运行的程序或批处理文件
    C++ 简单选择排序
    C++ 排序
    iOS UIDynamic
    iOS Modal
    C++ 折半查找
    C++ 二叉链表
  • 原文地址:https://www.cnblogs.com/tiancai/p/6050703.html
Copyright © 2011-2022 走看看