Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GET-parameters in MVC3 Controller

I was wondering how I can access the GET parameter in url's like ?returnTo=url

I'm using MVC3 with C# and would like to get the value in a Controller. I've snooped around in the Request object, which has the values I need in the "Query" property.

Do I have to parse that QueryString manually or is there an easier way?

like image 916
Geoffrey De Vylder Avatar asked Jan 26 '26 22:01

Geoffrey De Vylder


1 Answers

No, you don't have to parse manually. MVC3 uses model binding automatically. It means that if you add returnTo string parameter to your action method, MVC will automatically extract value from query string and initialize your action parameter. Default model binder tries to extract parameter values from Request.QueryString, Request.Form, RouteData. You can override or change part of behaviour if you implement custom model binder or register custom value provider. For more info take a look at Model Binding

like image 164
archil Avatar answered Jan 29 '26 12:01

archil