返回request......登陆

request参数集合绑定实体实现defaultmodebinder

巴扎黑2016-11-10 14:08:40556
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();
        }
    }
}

最新手记推荐

• 用composer安装thinkphp框架的步骤• 省市区接口说明• 用thinkphp,后台新增栏目• 管理员添加编辑删除• 管理员添加编辑删除

全部回复(0)我要回复

暂无评论~
  • 取消回复发送