Asp Net, MVC design patterns

intel intel 0 Reputation points
2025-03-22T19:20:25.59+00:00

Good afternoon,

I'm currently developing in ASP.NET using the MVC 5 framework, and I have SPA applications.

I want to migrate or unify my SPA applications into a single project. The project will have charts, reports, forms, and approximately 20 pages. I'd like to integrate a design pattern, but I don't know which one to use or what you recommend for a large application.

I'd appreciate any comments or examples that might help me with what I want to do.

Note:

I use jQuery and JS for my apps. I don't use React or Angular.

Developer technologies | ASP.NET | ASP.NET Core
{count} votes

3 answers

Sort by: Most helpful
  1. Jack Dang (WICLOUD CORPORATION) 4,945 Reputation points Microsoft External Staff Moderator
    2025-07-18T09:31:14.3566667+00:00

    Hi,

    Thanks for reaching out.

    To address your query about unifying your SPA applications into a single ASP.NET MVC 5 project with charts, reports, forms, and approximately 20 pages, I recommend the following approach to ensure scalability, maintainability, and a clean architecture tailored to your use of jQuery and JavaScript:

    For a large application like yours combining SPA functionality with ASP.NET MVC 5, the Repository Pattern combined with the Unit of Work Pattern is highly recommended. These patterns will help manage data access and business logic effectively while keeping your project organized.

    1. Repository Pattern: This pattern abstracts data access logic, making it easier to handle CRUD operations for your charts, reports, and forms. Create a generic repository interface to manage common data operations across your 20 pages. Implement specific repositories for each entity (e.g., Chart, Report, Form) to handle unique requirements, ensuring reusability and centralized data management.
    2. Unit of Work Pattern: Given the complexity of your project with multiple entities and potential transactions, the Unit of Work pattern will coordinate operations across repositories. This ensures all database changes within a business transaction are committed or rolled back together, maintaining data consistency.
    3. Dependency Injection (DI): Enhance testability and maintainability by integrating a DI framework like Autofac or Microsoft.Extensions.DependencyInjection. Use DI to inject repository and Unit of Work instances into controllers, decoupling them from data access implementations and making your application more modular.
    4. SPA Integration with jQuery/JS: Since you use jQuery and JavaScript (not React or Angular), host your SPA assets as static resources within the MVC project, served by a dedicated controller or view. Implement ASP.NET Web API to create RESTful endpoints for your SPA to retrieve data (e.g., for charts and reports). Your jQuery-based frontend can use AJAX calls to consume these endpoints, keeping the backend and frontend well-separated within one project.
    5. Project Structure: Organize your project with distinct folders for Models, Views, Controllers, Repositories, Services, and SPA assets (e.g., JavaScript, CSS). Place business logic in service classes that interact with repositories, keeping controllers lean. This structure aligns with MVC principles and supports your large-scale application.
    6. Scalability Considerations: For 20 pages with dynamic features, use ViewModels to shape data for your views, simplifying your jQuery frontend. For charts, integrate a JavaScript library like Chart.js, fetching data via Web API calls. Use a lightweight JavaScript router like Sammy.js for client-side navigation, given your preference for jQuery over modern frameworks.
    7. Testing and Maintenance: Implement unit testing for repositories and services using MSTest or NUnit, mocking dependencies with Moq. The DI setup will support this by allowing mock implementations during testing, ensuring robust development practices.
    8. Performance: Optimize for data-heavy features like reports by using asynchronous controllers and repository methods. Consider caching frequently accessed data (e.g., chart data) with in-memory caching or Redis if the application scales further.

    Start by exploring the Repository and Unit of Work patterns in ASP.NET MVC through resources like Microsoft’s Contoso University example. For your SPA setup, focus on building a robust Web API layer and leveraging jQuery for a seamless frontend experience.

    Hope this helps!

    1 person found this answer helpful.

  2. Bruce (SqlWork.com) 81,976 Reputation points Volunteer Moderator
    2025-03-23T16:53:31.9133333+00:00

    To build a SPA you need a couple technologies.

    • A routing component, so your SPA app can navigate between pages. You will need to pick a jquery routing component. jquery is not as popular as it once was for SPA, so many of the components are old. You might do better googling for a vanilla js library.
    • a template engine to be able to dynamically display your html. There are a lot of these.
    • a build tool chain that supports js modules. You will need to build your 20 pages into one via bundling. Webpack is the classic, but rollup or parcel may be a good choice.

    note: I use react and parcel, so can not recommend a jquery only solution. As a first step you might pick a build chain and convert all your JavaScript code to modules. This will make sharing easier.

    0 comments No comments

  3. Anonymous
    2025-04-04T03:21:36.15+00:00

    Hi @intel intel,

    I suggest you could consider using the MVVM/MVP pattern, you could design your client project, you could build a model(data), views(UI) and some logic to build your client projects.

    var ReportViewer = (function () {
        // Model (data)
        var reportData = [];
    
        // View (DOM manipulation)
        function render() {
            $("#reportContainer").html(/* generate HTML from reportData */);
        }
    
        // Logic to get the data
        function fetchData() {
            $.get("/api/reports", function (data) {
                reportData = data;
                render();
            });
        }
    
        return {
            init: fetchData
        };
    })();
    
    // Initialize module on page load
    $(document).ready(ReportViewer.init);
    

    Also you could use the some plugins to show the data and validate the input data, like chat.js and Jquery validation.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.