-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();
}
2

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.