Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7652151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:41:33+00:00 2026-05-31T11:41:33+00:00

Is it possible to create a Partial class for the controller in MVC? Reason

  • 0

Is it possible to create a Partial class for the controller in MVC?

Reason : I have a controller which contains too many code. This controller contains the code for different reports and due to too many code it reduces the readability of the code. I want to keep controller name same for all reports so I want to distribute code for the different reports.

If i can do any other way than do let me know.

Thanks
Alok Shah

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:41:35+00:00Added an answer on May 31, 2026 at 11:41 am

    Yes you can use a partial class – the compiler just merges them all up a compile-time to produce one.

    However, you mention you want to ‘distribute’ code – if the code is to go into multiple projects then partials are not going to help.

    You can instead create base controller classes (that inherit from System.Web.Mvc.Controller in a class library project, with the necessary action methods, and then simply use routing to route similar urls to different controllers. Here’s a link to the Asp.Net Tutorial ‘Creating Custom Routes’ which might be useful for that. I hightly recommend looking through the rest of the tutorial if there are other core aspects of MVC you’re not sure about. It doesn’t cover everything, but it does the basics.

    A web application that needs to use those then simply has its own controllers inherit from those redistributable ones. Even better, you can now create extensibility points through virtual methods etc if there are elements of these reports which different web apps might need to customise.

    So "Reports/Customers" could route to a CustomerReportsController and "Reports/Orders" could route to an OrdersReportsController:

    routes.MapRoute("CustReports",
      "Reports/Customers/{action}",
      new { controller = "CustomerReports", action = "Index", id = "" } );
    
    routes.MapRoute("OrderReports",
      "Reports/Orders/{action}",
      new { controller = "OrdersReports", action = "Index", id = "" } );
    

    This is the most simplistic approach to this problem – but I think using Areas (link is to MSDN walkthrough) would most likely also be applicable, in which case you might not need to use routing at all because the default route would probably do it all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to create a Partial View, which has a controller, which can
Consider we create a partial class in Project1 and we have a Project2 that
Is it possible to override an attibute set on a partial class? So I
I’m developing MVC application and I have following classes in my model: public class
Is it possible to create, in Scala, a type which is parametrized by a
I have this contact list which I'm building using LINQ to SQL. The query
I have DataTable which feeds a dropdown list. The values of this dropdown persist
Hi it'd like to know if it's at all possible create a parametric equalizer
Possible Duplicate: Create a temporary directory in Java Duplicate: stackoverflow.com/questions/375910 Is there a way
Possible Duplicate: Create Excel file in Java How to save output in excel format

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.