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 6674583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:45:47+00:00 2026-05-26T03:45:47+00:00

I am developing an MVC application using a mysql database. I searched a lot

  • 0

I am developing an MVC application using a mysql database.

I searched a lot through SO and other sites about the architecture/structure. I found a lot of similar questions but I am still in doubt.

In my applications there is a categories section; the structure is shown below:

View:

Category – (views in category folder listed below)

        CreateCategory
      
        DeleteCategory

        ManageCategory

    

Controller:

CategoryController – (action names listed below)

        CreateCategory
      
        DeleteCategory

        ManageCategory

Model: This is where I have doubts. I have a model named CategoryModels but I don’t know if I doing things the right way or not. I don’t know where I should put the service functions – for example where I put functions to create or delete categories.

What I did is create a CategoryServices class inside CategoryModel.cs and write functions inside that. DAL file is put in app code folder, so to access the DB the function will create an object of DAL and call it. Is this the right way?

In CategoryModels.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Web.Mvc;
using System.Web.Caching;

namespace TraktorumMVC.Models
{
    public class CategoryModels  // contain properties for the 3 views (CreateCategory,DeleteCategory and  ManageCategory
    {
          public IEnumerable<SelectListItem> CategoryList { get; set; }
          public IEnumerable<SelectListItem> AvailableCategories { get; set; }
           //etc..........
    }

    public class CategoryServices  // this class contain all service functions related to categories   
    {
       public int RemoveCategory(int categoryId) // this will remove a category
       {            
        int status = -1;
        try
        {
            string query = Resources.Queries.RemoveCategory;
            DAL objDAL = new DAL();               //DAL file is in Appcode folder. IS this right way
            string[] inParamNameArray = { "Id"};
            string[] inParamValueArray = { categoryId.ToString()};
            object[] inParamTypeArray = { DbType.Int32 };
            status =Convert.ToInt32( objDAL.ExecuteScalar(query, inParamNameArray, inParamValueArray, inParamTypeArray, true));               
        }
        catch (Exception ex)
        {
            DeveloperLog.WriteExceptionLog(ex, "CategoryServices.RemoveCategory");
        }
        
        return status;
      }

       public bool InsertCategory(int parentCategoryId, string icon, string name)
       {
        //bla bla
       }
    }
}

Is this right way to do this? Did this break the model concept?

  • 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-26T03:45:47+00:00Added an answer on May 26, 2026 at 3:45 am

    The “Model” in ASP.NET MVC is not very prescriptive, and is certainly less prescriptive than the Views or Controllers.

    That said, there isn’t necessarily a right or wrong way to do your model, but there are a few popular/common approaches that people take:

    • Leverage an ORM like Entity Framework (EF) or NHibernate to be your model. This works out well on simple sites that are mostly CRUD driven. In your situation, EF could handle all of the CRUD work you need to do on categories.
    • Another common approach to is to leverage some sort of services layer which might encapsulate business and data access logic. This layer might return to your application data transfer objects – very simple, data only containers – that you can change and send back.
    • Either way, it’s a good idea to separate your “View Model” from your “Domain Model”. An example of this is not simply passing Entity Framework controlled objects to the View for rendering. Instead you’d map those objects (and potentially others) into a “View Model” specifically created for just that view. A popular tool to help developers accomplish this is the excellent http://automapper.org/

    In your situation, if you can, I’d recommend putting in an ORM to handle the persistence of categories. If your current DAL is doing more than just persistence, then I’d recommend you separate it out to a service, with corresponding interface, that your controller can get a reference to and use to drive your application forward.

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

Sidebar

Related Questions

I am developing an MVC application using nHibernate; running through VS's built in web
I am currently developing an MVC application in ASP.net. I am using AJAX.ActionLink to
I am developing an application using MVC Preview 5. I have used typed views.
I am developing an application using Asp.net mvc and jquery. I'd like to use
We're developing quite a big application using ASP.NET MVC and at the beginning we
I'm developing a web application using ASP .NET MVC 1.0 and jQuery (including the
We are developing an ASP.NET MVC Application that currently uses it's own database ApplicationData
I'm developing an website using asp.net mvc with MySQL and I need to make
I'm developing Asp.MVc 2 application. In solution i've about 10 projects and i have
I'm developing an application using asp.net mvc, NHibernate and DDD. I have a service

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.