How to get query string variables in MVC 4's Request?

后端 未结 2 581
耶瑟儿~
耶瑟儿~ 2021-02-14 15:08

I\'m guffawed here working on my first MVC 4 project with the Web Api variety.

In MVC 3 I could get a query string parameter like such:

var unicornName          


        
相关标签:
2条回答
  • 2021-02-14 15:15

    If the linq is really that troublesome, just wrap the result of your GetQueryNameValuePairs() in a dictionary:

    var requestQuery = 
        list.ToDictionary((keyItem) => keyItem.Key, (valueItem) => valueItem.Value);
    

    You can then get your string parameter just like you always have:

    var unicornName = requestQuery["unicornName"];
    
    0 讨论(0)
  • 2021-02-14 15:38

    I think this may be what you are looking for,

      var queryValues = Request.RequestUri.ParseQueryString();
    

    https://stackoverflow.com/a/11729619/6819

    0 讨论(0)
提交回复
热议问题