-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
760k186 gold badges1.4k silver badges1.5k bronze badges
asked Oct 26, 2017 at 16:24
2

2 Answers 2

3

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

answered Oct 26, 2017 at 16:28
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

answered Oct 26, 2017 at 16:29

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.