Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is the answer to keep your controller simple and still having good url patterns:</p> <p><strong>Controller:</strong></p> <pre><code> public class InvitationController : Controller { public ActionResult GetAllBusStops() { //Logic to show all bus stops //return bus stops return View(); } public ActionResult GetBusStopById(string id) //Assumed your id to be a string { //Logic to get specific bus stop //return bus stop return View(); } public ActionResult GetAllDrivers() { //Logic for driver list //return driver list return View(); } public ActionResult GetDriverById(int id) //Assumed your id to be an integer { //Logic to get specific driver //return driver return View(); } public ActionResult GetDriver(string city, string model,int limit) //Assumed datatypes { //Logic to get specific driver with this criteria //return driver return View(); } public ActionResult GetAllQuestionairs() { //Logic for questionair list //return the list return View(); } public ActionResult GetQuestionairById(int id) //Assumed your id to be an integer { //Logic to get specific questionair //return it return View(); } public ActionResult CreateQuestionair(QuestionairCreateModel model) { //logic to create questionair return View(); } public ActionResult GetQuestionairById(int id) //Assumed your id to be an integer { //Logic to get specific questionair //return it return View(); } public ActionResult UpdateQuestionairById(int id) //Assumed your id to be an integer { //Logic to update specific questionair //return it return View(); } } </code></pre> <p>Now go to your <code>App_Start</code> Folder, Open <code>RouteConfig.cs,</code> start adding the REST urls in the routes as below:</p> <pre><code>routes.MapRoute( "List Bus Stops", // Route name "invitation/mission/busstop", // No parameters for Getting bus stop list new { controller = "Invitation", action = "GetAllBusStops"}, // Parameter defaults new { httpMethod = new HttpMethodConstraint("GET") } ); routes.MapRoute( "Get Bus stop by id", // Route name "invitation/mission/busstop/{id}", // URL with parameters new { controller = "Invitation", action = "GetBusStopById" }, // Parameter defaults new { httpMethod = new HttpMethodConstraint("GET") } ); routes.MapRoute( "Get All Drivers", // Route name "invitation/mission/driver", // No parameters for Getting driver list new { controller = "Invitation", action = "GetAllDrivers"}, // Parameter defaults new { httpMethod = new HttpMethodConstraint("GET") } ); routes.MapRoute( "Get Driver by id", // Route name "invitation/mission/driver/{id}", // URL with parameters new { controller = "Invitation", action = "GetDriverById" }, // Parameter defaults new { httpMethod = new HttpMethodConstraint("GET") } ); routes.MapRoute( "Get driver for city, model, limit", // Route name "invitation/mission/driver/{city}}/{model}/{limit}", // URL with parameters new { controller = "invitation", action = "GetDriver"}, // Parameter defaults new { httpMethod = new HttpMethodConstraint("GET") } ); routes.MapRoute( "Get All Questionairs", // Route name "invitation/questionair", // No parameters for Getting questionair list new { controller = "Invitation", action = "GetAllQuestionairs"}, // Parameter defaults new { httpMethod = new HttpMethodConstraint("GET") } ); routes.MapRoute( "Get questionair by id", // Route name "invitation/questionair/{id}", // URL with parameters new { controller = "Invitation", action = "GetQuestionairById" }, // Parameter defaults new { httpMethod = new HttpMethodConstraint("GET") } ); routes.MapRoute( "Create New Questionair, // Route name "invitation/questionair/create", // URL with parameters new { controller = "invitation", action = "CreateQuestionair" }, // Parameter defaults new { httpMethod = new HttpMethodConstraint("POST") } ); routes.MapRoute( "Update Questionair, // Route name "invitation/questionair/update/{id}", // URL with parameters new { controller = "invitation", action = "UpdateQuestionairById" }, // Parameter defaults new { httpMethod = new HttpMethodConstraint("POST") } ); </code></pre> <p>Many things are assumed like the datatypes and model names. You can figure out how it works from this....</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