0

I have these classes.

Secion Repository
Section Application
Section Controller
Group Repository
Group Application
Group Controller
Class Repository
Class Application
Class Controller

and all of my controllers have a view named Show And these structure of entities. enter image description here

Now the question is this: I want when I go to the Class controller I see

Class/Show/class's group's section name/class's group name/class's name

instead of

Class/Show/1

or when I go to the Group controller I see

Group/Show/group's section name/group name

instead of

Group/Show/1

How?

1 Answer 1

1

You can define the following route:

routes.MapRoute(
    "ShowRoute",
    "{controller}/show/{groupsection}/{groupname}/{classname}",
    new { controller = "class", action = "show", classname= UrlParameter.Optional },                
);

A few things to note:

  1. You can choose any controller to be the default (e.g. controller="the_default")
  2. You can declare all parameters as optional but you need to take care of null arg values in your code

You can then define your controller methods like this:

public ActionResult Show(string groupsection, string groupname, string classname) {    
}

And then have the following requests:

http://your_domain/class/group1-section5/group1/class-obedient

http://your_domain/group/group1-section5/group1/
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.