Asp.Net MVC Action methods and URLs

  Total Views : 3835
  Comments : 0
 
  Keywords : How to define urls in mvc, How to use action methods and urls in asp.net mvc

Here we will learn what are the action methods in asp.net mvc and how to define urls for action method in asp.net mvc with example.

Action Methods & Urls in Asp.Net MVC

Let’s start understanding what Action method is? when any user want to access website or application in asp.net mvc user enter URL in browser like as shown below

 

E.g.  http://localhost:7575/PersonDetails/Index

 

In above URL you can see that PersonDetails is controller and Index is action method which user is entering to invoke action method index by enter this URL in browser.

 

URLControllerActionID
/PersonDetails/Index PersonDetails Index  

 When controller gets request by browser that controller will invoke method inside it . In case if method not found in controller then it will popup error saying http not found exception.

Controller with Action Methods in Asp.Net MVC 

The method with ActionResult in asp.net mvc is called as Action Methods which return various View Results. For example following is the PersonDetailsController code snippet. You will see that Controller is a Class and Index is a Method in side that class. Here Index is the action method of PersonDetailsController

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Mvc;

using Tutorial3.Models;

 

namespace Tutorial3.Controllers

{

public class PersonDetailsController : Controller

{

//

// GET: /PersonDetails/

[HttpGet]

public ActionResult Index()

{

return View(newPerson());

}

}

}

This is how we can define action methods and urls for action methods in asp.net mvc application.

 Comments (0)

Be the first to give your valuable feedback

Leave a comment

  • Default Tutlane User