Skip to main content

Posts

Showing posts from January, 2018

MVC – Action Verbs

   MVC – Action Verbs Action Selectors ·          Action selector is the attribute that can be applied to the action methods. It helps routing engine to select the correct action method to handle a particular request. MVC 5 includes the following action selector attributes: o     ActionName o     NonAction o     ActionVerbs ActionName ·          ActionName attribute allows us to specify a different action name than the method name. public class EmployeeController : Controller { public EmployeeController() { } [ ActionName ( "find" )] public ActionResult GetById( int id) { // get employee from the database return View(); } } ·          In the above example, we have applied ActioName("find") attribute to GetById action method. So now, action name is "find" instead of "GetById". This action method will be invoked on http://localhost/employee/find/1 request instead of http:/

MVC – Action Result Methods

   MVC – Action Result Methods Action Method ·          All the public methods of a Controller class are called Action methods. They are like any other normal methods with the following restrictions: o     Action method must be public. It cannot be private or protected o     Action method cannot be overloaded o     Action method cannot be a static method. Default Action Method: ·          Every controller can have default action method as per configured route in RouteConfig class. By default, Index is a default action method for any controller, as per configured default root as shown below. routes.MapRoute(     name: "Default" ,     url: "{controller}/{action}/{id}/{name}" ,     defaults: new { controller = "Home" ,                     action = "Index" ,                     id = UrlParameter .Optional             }); ActionResult