How to Create MVC Outbound URL

When we talk about web applications, users would be our first priority. Our applications should be easy to navigate from page to page, so, as a developer, our goal is to give a reasonable name for every page. However, creating a user-friendly page sometimes becomes in conflict with MVC principles. According to the MVC principle, it should first come to the controller but by using the suggested method earlier, it bypasses your controller logic and your MVC architecture will be completely useless.

Hyperlinks should have actions in the anchor tags and not page names. To do that, we need to perform the following.

1. Create views with a simple navigation between pages.
2. Create a controller for the view. This snippet below will help you do that:
public class SiteController : Controller

{
//
// GET: /Site/

public ActionResult GotoHome()
{
return View("Home");
}

public ActionResult AboutUs()
{
return View("About");
}

public ActionResult SeeProduct()
{
return View("Product");
}
}

3. Provide actions in the link. Rather than the views, we need to specify the action in the anchor tag.

4. Enjoy your navigation. Test it to see if it works.

Read the rest of the tutorial here: http://www.dotnetfunda.com/articles/article1596-how-to-create-mvc-outbound-urls-mvc-tutorial-number-9-.aspx

Leave a Reply

Your email address will not be published. Required fields are marked *