Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC Url Routing

I want to generate URL like.. It should include two IDs with employer and job including. I am confused and have no idea about it. I have a controller Employer.

http://localhost/Employer/[employerID]/job/[jobid]
like image 776
k-s Avatar asked Feb 09 '26 22:02

k-s


1 Answers

routes.MapRoute(
    "EmplyerJob", // Route name
    "Employer/{empid}/job/{jobid}",
    new { controller = "Employer",
          action = "Job" }
);

I have made a few changes to Xander's answer. I don't think you'll want to use parameters here, as this will throw off other routes to other controllers/action methods. If you use the hard-coded "Employer" and "job" strings, you will be narrowing down what routes are analyzed by this route.

Also, you can't have an optional parameter before a required parameter.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!