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.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
-
- namespace MvcApplication5.Controllers
- {
- public class HomeController : Controller
- {
-
-
- public ActionResult GetEmpName()
- {
- return Content("This is the test Message");
- }
-
- [ActionName("GetEmpWithCode")]
- public ActionResult GetEmpName(string EmpCode)
- {
- return Content("This is the test Messagewith Overloaded");
- }
-
- }
- }
Now to run the controller GetEmpName action method with just give the URL like this:
http://localhost:49389/Home/GetEmpName.
Now to run the controller GetEmpWithCode action method with just give the URL like this:
http://localhost:49389/Home/GetEmpWithCode.