Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Partial Controller in MVC
WhatsApp
Pramod Thakur
9y
46.5
k
0
0
25
Blog
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.
using
System.Web.Mvc;
namespace
HtmlInjectInMvc.Controllers
{
public
partial
class
ABCController: Controller
{
public
ActionResult Index()
{
return
View();
}
}
}
Now add a view and name it Index.
Now add another controller and name it xyzController. In xyzController.cs
using
System.Web.Mvc;
namespace
HtmlInjectInMvc.Controllers
{
public
class
xyzController: Controller
{
public
ActionResult Index()
{
return
View();
}
}
public
partial
class
ABCController: Controller
{
public
ActionResult About()
{
ViewBag.Name =
"Prmaod Kumar"
;
return
View();
}
}
}
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 :)
Partial Controller in MVC
Up Next
Auto Refresh a Partial View of a Page in MVC
Ebook Download
View all
Diving Into ASP.NET WebAPI
Read by 21.4k people
Download Now!
Learn
View all
Membership not found