I developed an MVC application and now I need to make some changes. I would like to pass additional parameters and the format of URL cannot be changed. Initially the URL looked like http://url.com/product/1001 Now It has to be http://url.com/product/1001?type=1
How do I parse type=1 in my Controller module. Kindly help
You can simply add it to the action method signature:
public ActionResult MyMethod(string type)
{
}
Route, QueryString, Form, and other values automatically get bound to action method signatures if the naming matches and a conversion is possible (so int?
would also be a valid type for type
).
If you don't want to do that, you can always fall back to the ever reliable Request.QueryString[]
NameValueCollection.
string type = Request.QueryString["type"];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With