I am new to the ASP.NET MVC framework. I am trying to get data from url parameters, then from my controller I want to return with ViewBag.
But the problem is, when I type that url in the browser, in debug mode, the data is not being returned correctly. Please have a look at
to see debug results. Any idea what's wrong here?
The Url I am using is:
http://localhost:60617/CategoryResearch/test/name=john?id=33
My controller:
public ActionResult test(string name, string id)
{
ViewBag.name = name;
ViewBag.id = id;
return View();
}
-
2There are multiple issues in your code, your default route is expecting id as parameter and so taking 'name=john' as parameter value. you should create a custome route and use url as localhost:60617/CategoryResearch/test/john/33ssilas777– ssilas7772017年10月26日 16:28:05 +00:00Commented Oct 26, 2017 at 16:28
-
Possible duplicate of Routing with Multiple Parameters using ASP.NET MVCChristian Gollhardt– Christian Gollhardt2017年10月26日 16:31:24 +00:00Commented Oct 26, 2017 at 16:31
2 Answers 2
Url does not look right to me.
Try /CategoryResearch/test?name=john&id=33.
Comments
Your route seems to be setup to pull the id from the URL path, which is why it's getting the entire value of the last step in the path ("name=john").
I think you either need to pass the actual id number in the URL path like this:
http://localhost:60617/CategoryResearch/test/33?name=john
or you need to move all parameters into the query string:
http://localhost:60617/CategoryResearch/test?name=john&id=33