Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.net MVC Routes
    text
    copied!<p>I am currently creating a mobile version of my company's site and using it as a time to learn asp.net mvc.</p> <p>The URLs which I'm meant to be creating are as follows</p> <p>Jobs/in/location <br /> Jobs/for/jobTitle <br /> Jobs/in/location/for/jobtitle <br /> jobs/for/jobtitle/in/location <br /></p> <p>Now the more types we add the more I'll need to add and different routes I'll need, so not really maintaining.</p> <p>So currently in my Global.asax.cs is</p> <pre> <code> //Jobs routes.MapRoute( "DefaultJobs", // Route name "Jobs/{pagenumber}", // URL with parameters new { controller = "Jobs", action = "Default", pagenumber = "1" } // Parameter defaults ); //Jobs by Location routes.MapRoute( "JobsByLocation", // Route name "Jobs/in/{location}/{pagenumber}", // URL with parameters new { controller = "Jobs", action = "Default", location = "", pagenumber = "1" } // Parameter defaults ); //Jobs by Title routes.MapRoute( "JobsByTitle", // Route name "Jobs/for/{title}/{pagenumber}", // URL with parameters new { controller = "Jobs", action = "Default", title= "", pagenumber = "1" } // Parameter defaults ); //Jobs by Title and Location routes.MapRoute( "JobsByTitleAndLocation", // Route name "Jobs/for/{title}/in/{location}/{pagenumber}", // URL with parameters new { controller = "Jobs", action = "Default", location = "", title = "", pagenumber = "1" } // Parameter defaults ); </code> </pre> <p>So I'm not sure if this is right, since in my JobsController I did have "in" as a Controller, but I could only get one parameter. So I went with a default one which caught everything.</p> <pre><code> public ActionResult Default(string location, string title, string pagenumber) { return Content("Location " + location + " Title " + title + " Page " + pagenumber); } </code></pre> <p>Now is this the right way of doing it? Or have I missed something?</p> <p>For calling this method, I have this</p> <pre><code> [AcceptVerbs(HttpVerbs.Post)] public ActionResult SearchContinent(string Continents) { try { // TODO: Add update logic here //return RedirectToAction("Default","Jobs", //new { // location = Continents // }); return RedirectToRoute(new { controller = "Jobs", action = "Default", location = Continents, pagenumber = "1" }); //return Redirect("Jobs/in/" + Continents); } catch { return View(); } } </code></pre> <p>Now this doesn't produce the correct url since it is missing the "in" and passes "location" as a param, which works but is incorrect.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload