2

I'm trying to learn MVC and having a rough start.

routes.MapRoute(
       "Test",
       "Test/{stringInput}",
       new { controller = "Test", action = "TestMethod", stringInput = "" }
);

doesn't pass stringInput to the method TestMethod in the controller. It comes over null.

Not sure what I'm missing, it seems very simple and straightforward. This route was placed above the default.

1
  • I have followed the execution of this through to the controller. The route is set up properly, just not passing the variable stringInput to the controller for whatever reason. Commented Aug 4, 2009 at 20:12

3 Answers 3

3

Override the Execute method of your controller and then put a breakpoint in it so you can see the request context. One of the properties is the key/value pair being passed in. Make sure the key for stringInput has the correct value.

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

1 Comment

Thank you, this helped me immensely in figuring out that I did not use the same parameter name in the signature of my controller method which is the issue...
1

Make sure your controller is setup properly. It should be in folder

Controllers/TestController.cs

and inside the controller should be

public ActionResult TestMethod( string stringInput )
{
    return View();
}

It uses conventions, so the naming you setup in your route needs to match the files, methods, and parameters of the controller.

The url to get to this should be

/Test/TestMethod/MyStringInput

and "MyStringInput" would be the value of the variable stringInput.

Comments

0

Are you sure that route is the one being used? Try moving it to the top of your list of routes to make sure.

1 Comment

Yes, I've followed it in the debugger.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.