ASP.NET MVC - Extract parameter of an URL

后端 未结 6 1944
轮回少年
轮回少年 2020-12-12 20:26

I\'m trying to extract the parameters of my URL, something like this.

/Administration/Customer/Edit/1

extract: 1

/Adm

6条回答
  •  感动是毒
    2020-12-12 21:17

    I wrote this method:

        private string GetUrlParameter(HttpRequestBase request, string parName)
        {
            string result = string.Empty;
    
            var urlParameters = HttpUtility.ParseQueryString(request.Url.Query);
            if (urlParameters.AllKeys.Contains(parName))
            {
                result = urlParameters.Get(parName);
            }
    
            return result;
        }
    

    And I call it like this:

    string fooBar = GetUrlParameter(Request, "FooBar");
    if (!string.IsNullOrEmpty(fooBar))
    {
    
    }
    

提交回复
热议问题