Reputation: 4404
I have this method in my Home controller:
public ActionResult RequestExamReview(string EC)
I have this link in my view (in debug mode):
http://localhost:50909/Home/RequestExamReview/201507LH123
But when I debug into the method and check EC, it is null.
What am I doing wrong? I'm using the default routing, do I need to create a new route definition:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
Upvotes: 0
Views: 35
Reputation: 406
You have a couple options:
You can name the parameter in your method "id" like it is defined in your route
public ActionResult RequestExamReview(string id)
You can specify a new route that has the value ec as a parameter (but I wouldn't recommend this)
If you were to do that it would look something like this:
routes.MapRoute(
name: "Default",
url: "Home/RequestExamReview/{ec}",
defaults: new { controller = "Home", action = "RequestExamReview" }
);
http://localhost:50909/Home/RequestExamReview?EC=201507LH123
Bind
attribute to rename your parameter to idpublic ActionResult RequestExamReview([Bind(Prefix="id")] string EC)
I wouldn't recommend adding a new route because it is best to keep the number of routes small to reduce complexity. You will find that as your app grows, managing the number of routes will become painful if you add a new route just to custom name your variables. In your case I would recommend just using the url with the query string values.
Upvotes: 3