For some reason, whenever I try to resolve a URL with arguments in my local installation of ASP.NET MVC3, the arguments basically end up being null in my controller’s handling function.
For example, I have
public class HomeController : Controller
{
public ActionResult Foo(string bar)
{
ViewBag.Message = bar;
return View();
}
}
and try to visit http://localhost/myapp/foo/sometext or http://localhost/myapp/home/foo/sometext, bar basically evaluates to null instead of sometext.
I’m fairly confident that my MVC3 install is working properly, as I’ve managed to run a separate app with a custom routing rule just a few days back. I’m kind of wary that I might have botched up a config flag somewhere or whatever.
Any ideas on what could be wrong here?
The default route mapping expects a parameter named
idin your action.If you change your action to this:
it should work. You could also try a URL like this if changing the parameter name isn’t possible: