How to Overload the Action Method in ASP.NET MVC

If we have to overload the action Method in asp.net MVC then we can not do it directly. We have to change the ActionName like this code snippet.

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.Mvc;  
  6.   
  7. namespace MvcApplication5.Controllers  
  8. {  
  9.     public class HomeController : Controller  
  10.     {  
  11.          
  12.   
  13.         public ActionResult GetEmpName()  
  14.         {  
  15.             return Content("This is the test Message");  
  16.         }  
  17.   
  18.         [ActionName("GetEmpWithCode")]  
  19.         public ActionResult GetEmpName(string EmpCode)  
  20.         {  
  21.             return Content("This is the test Messagewith Overloaded");  
  22.         }  
  23.   
  24.     }  
  25. }  
Now to run the controller GetEmpName action method with just give the URL like this:
http://localhost:49389/Home/GetEmpName.

local host

Now to run the controller GetEmpWithCode action method with just give the URL like this:
http://localhost:49389/Home/GetEmpWithCode.

run the controller GetEmpWithCode

Ebook Download
View all
Learn
View all