js、C#获取Url所有参数

一、js获取地址栏参数

例如:http://localhost/SpaceBIA.Case.ZJG.Agriculture/ProductSale/SearchProduct?keyType=%E5%95%86%E5%93%81&keyWord=%E6%B2%B9%E9%BA%A6%E8%8F%9C

    var LocString = String(window.document.location.href);
    //获取当前url中的参数
    function GetQueryString(name) {
        var rs = new RegExp("(^|)" + name + "=([^&]*)(&|$)", "gi").exec(LocString), tmp;
        if (tmp = rs) return tmp[2];
        return null;
    }

    var keyType = decodeURI(GetQueryString("keyType"));//搜索类型,返回值:商品
var keyWord = decodeURI(GetQueryString("keyWord"));//搜索关键字,返回值:油麦菜

 

二、C#获取MVC路径参数

例如:http://localhost/SpaceBIA.Case.ZJG.Agriculture/AgrCorporations/Edit/787fe0a0-5dad-461f-ac7e-0367749245fc

var filterContext = new System.Web.Mvc.ActionExecutingContext();

//控制器名称,返回值AgrCorporations
var controllerName = (filterContext.RouteData.Values["controller"]).ToString().ToLower();    

//视图名称,返回值Edit
var actionName = (filterContext.RouteData.Values["action"]).ToString().ToLower();

//id,返回值787fe0a0-5dad-461f-ac7e-0367749245fc
var urlID = (filterContext.RouteData.Values["id"] == null ? "" : filterContext.RouteData.Values["id"]).ToString().ToLower();  

 

 
posted @ 2017-12-22 15:54  付刚的博客  阅读(2335)  评论(0编辑  收藏  举报