-1

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

picture1

picture2

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();
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
John Lk
  • 185
  • 2
  • 15
  • 2
    There 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 http://localhost:60617/CategoryResearch/test/john/33 – ssilas777 Oct 26 '17 at 16:28
  • Possible duplicate of [Routing with Multiple Parameters using ASP.NET MVC](https://stackoverflow.com/questions/2246481/routing-with-multiple-parameters-using-asp-net-mvc) – Christian Gollhardt Oct 26 '17 at 16:31

2 Answers2

3

Url does not look right to me. Try /CategoryResearch/test?name=john&id=33.

danyloid
  • 1,677
  • 3
  • 21
  • 47
2

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

claylong
  • 51
  • 3