Partial Controller in MVC

Can we make controller as partial ?

Yes, we can make controller as partial.

Lets create a mvc application. Now create a contolller and name it "ABCController".

Now make the controller as partial.
  1. using System.Web.Mvc;    
  2. namespace HtmlInjectInMvc.Controllers    
  3. {    
  4.     public partial class ABCController: Controller    
  5.     {    
  6.         public ActionResult Index()     
  7.         {    
  8.             return View();    
  9.         }    
  10.     }    
  11. }  
Now add a view and name it Index.

Now add another controller and name it xyzController. In xyzController.cs
  1. using System.Web.Mvc;    
  2. namespace HtmlInjectInMvc.Controllers    
  3. {    
  4.     public class xyzController: Controller    
  5.     {    
  6.         public ActionResult Index()     
  7.         {    
  8.             return View();    
  9.         }    
  10.     }    
  11.     public partial class ABCController: Controller    
  12.     {    
  13.         public ActionResult About()     
  14.         {    
  15.             ViewBag.Name = "Prmaod Kumar";    
  16.             return View();    
  17.         }    
  18.     }    
  19. }  
Now add a view for xyzController and name it index. Add a view and name it about.

Now run the application.

Output





Hope enjoy this article.

Happy coding :)