Reputation: 16764
I have this simple javascript code:
var value = "I love programming";
window.location="Controller/Action/"+value;
In controller page, I have this:
public ActionResult(string value) {
// do something
}
The problem is value
parameter from controller. This is always null.
Why ?
Is the parameter type is restricted to int? (without using ajax)
I can send an int to controller and it process the information correctly. But not string.
Upvotes: 2
Views: 2007
Reputation: 22485
You may need to set up a route in global.asax to handle the string parameter, i.e:
RouteTable.Routes.MapRoute(
"ValueRoute",
"{controller}/{action}/{value}",
new
{
controller = "Yourcontroller",
action = "Youraction",
value = UrlParameter.Optional
}
);
this is all top of the head stuff, so it may not happen for you.
[update 1] as you say in the comment below, changing the parameter name from value=>id should resolve the problem without recourse to addtional routes.
[update 2] - you could also, as per sandeep's comment, opt for the name-value pair on the url, i.e. window.location="Controller/Action?value="+yourValue
Upvotes: 3