2 Replies - 1731 Views - Last Post: 20 February 2015 - 10:25 AM

#1 complete   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 115
  • Joined: 12-April 07

How do I make a MVC project?

Posted 20 February 2015 - 09:41 AM

How do I make a MVC project? I understand the logic of this sort of structure. I have seen some blogs and explanations and even code segments explaining how a program can use MVC. But I want to know what is a good way to represent a Model-View-Controller program in the Visual Studio.

For example, in an ASP.NET program, the asp.net file is associated with a C# file. THey have the same name and, in the Solution Explorer window of the Visual Studio development environment, they are shown linked together where one is a tree branch of the other. Should the same sort of thing be done for a MVC solution? I can remember a few years ago, I worked on a MVVM project, and a developer who first put the solution file together actually had view and the view-model files arranged like this. In order to make this happen, he had to download some sort of patch that allowed him to edit the .sln (solution) file.

Is that the way to go for a Model-View-Controller program? Should each be its own workspace in the solution, or should the solution file be edited such that each Model-View-Controller coupling be handled as a tree structure file representation kind of like it is done for an ASP.NET solution?

Here is another question. What is a good template to use in Visual Studio to create an example of a Model-View-Controller program? I tried this route but when I clicked to "get new templates", it did not work:



Is This A Good Question/Topic? 0
  • +

Replies To: How do I make a MVC project?

#2 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: How do I make a MVC project?

Posted 20 February 2015 - 09:58 AM

We like to have images actually on this site and visible in the post, rather than make people have to go load them, and risk them disappearing from some other site. In the future could you please ATTACH the photo to your post so they are here for future visitors looking for answers to the same/similar question?

Attached Image

Attached Image

When I google "C# MVC project" one of the first hits is the walkthrough on the MSDN site.

Did you even try doing a search for a tutorial?

But I also see you are looking at WinForms templates. So now I'm confused. Are you looking to make an ASP.NET website or a desktop application?
If you are looking to make a website then look at the MSDN link I have you.
If you are looking to make a desktop application then you want to get away from the old-school 1990's WinForms/MVC model and move to the modern WPF/MVVM pattern. Just thing of MVVM as the more updated MVC.
Was This Post Helpful? 0
  • +
  • -

#3 djjeavons   User is offline

  • D.I.C Regular
  • member icon

Reputation: 114
  • View blog
  • Posts: 417
  • Joined: 09-January 09

Re: How do I make a MVC project?

Posted 20 February 2015 - 10:25 AM


Not sure on what version of Visual Studio you are running but ASP.NET MVC has templates that are installed into Visual Studio for building the solution structure and other bits for you.

A standard MVC application will consist of one project containing the following:

  • Models folder - classes that represent the Models
  • Controllers folder - classes that represent the controllers
  • Views folder - either Aspx or cshtml (or vbhtml for VB.NET) files depending on wether you are using Razor or not
  • Scripts folder for all your script files
  • Css folder for your style sheets
  • App_Data folder for local databases
  • Others

There really isn't any concept in MVC of a designer file associated with a code behind file like there is in ASP.NET WebForms. You can however mix WebForms and MVC in the same app but if you are looking to build a greenfield project I wouldn't recommend it.

The above is pretty standard and is fine in most cases. If you are building large applications you may want to consider other structures. For example, one very large site I developed with MVC 2.0 had the following structure:

Started with an empty solution then added the following projects:

DAL - this is a class library project that contained all of the actual database communication code. This simply retrieved tables or data rows and executed stored procedures.

Repositories - this is a class library project that references the DAL project and Models project and is the only thing that talks to the DAL. Its responsibility is to take a model and update it or to get data and return a single or multiple models.

Services - this is a class library project that contains all of the business logic and references the Models and Repositories projects.

Models - this is a class library project and contains all model classes. These classes are standard POCO objects that also contain self validation.

Each of these projects were also complimented with test projects.

Then we have the MVC site, in the way I described above. The only difference is that we removed the Models folder as it was not needed. The site references the Models and Services projects. The controllers would talk to the service to get data (models) and pass to the view or to take a model and pass to the service. They very rarely did anything else as this was all encapsulated lower down.

This type of structure works well, especially when testing both at unit level and browser level.

Hope this provides you with the info you were looking for.
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1