Reputation: 14520
I have two routes I'm trying to create to use like
www.mysite.com/Rate/Student/Event/123
www.mysite.com/Rate/Teacher/Event/1234
routes.MapRoute(
name: "Rate",
url: "Rate/Student/Event/{id}"
);
routes.MapRoute(
name: "Rate",
url: "Rate/Teacher/Event/{id}"
);
How do I construct the action methods?
Here is what I have in my Rate controller
public ActionResult Student(int id)
{
return View();
}
public ActionResult Teacher(int id)
{
return View();
}
Upvotes: 1
Views: 688
Reputation: 56849
You have set up routing to match the URL, but you haven't told MVC where to send the request. MapRoute works by using route values, which can either be defaulted to specific values or passed through the URL. But, you are doing neither.
NOTE: The
controller
andaction
route values are required in MVC.
routes.MapRoute(
name: "Rate",
url: "Rate/Student/Event/{id}",
defaults: new { controller = "Rate", action = "Student" }
);
routes.MapRoute(
name: "Rate",
url: "Rate/Teacher/Event/{id}",
defaults: new { controller = "Rate", action = "Teacher" }
);
routes.MapRoute(
name: "Rate",
url: "{controller}/{action}/Event/{id}"
);
Upvotes: 4