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

后端 未结 2 580
耶瑟儿~
耶瑟儿~ 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"];
    

提交回复
热议问题