What is Attribute Routing in Asp.Net Mvc...?
There are two type of Attribute Routing.
1) Controller
Level routing
2) Action
level routing
1) Controller level routing.
[RoutePrefix("UserMaster")] //New controller Name [Route("{action=index}")] //default action public class UserController : Controller { //new route: /UserMaster/Index public ActionResult Index() { return View(); } //new route: /UserMaster/List public ActionResult List() { return View(); } }
2) Action level routing
public class UserMasterController : Controller { //route: /UserMaster/About public ActionResult About() { return View(); } [Route("users/IndexOfUser ")] //route" /users/IndexOfUser public ActionResult Index() { return View(); } [Route("users/{id}")] //eg: /users/1 public ActionResult List(int id) { return View(); } [Route("users/{id}/List")] //route" /users/1/List public ActionResult List(int id) { return View(); } }
Thanx for whatching tutorial......shared with your frinds
No comments
Post a Comment