1

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();
}

1 Answer 1

4

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 and action route values are required in MVC.

Option 1: add default route values.

    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" }
    );

Option 2: pass the route values through the URL.

    routes.MapRoute(
        name: "Rate",
        url: "{controller}/{action}/Event/{id}"
    );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.