Dut_21326719_E
Dut_21326719_E

Reputation: 11

MVC explanation and usuage

We are currently learning how to use c# at university, and we have been given a project that uses mvc, I would like to know what mvc is all about and how do we implement it? Any suggestions will be appreciated

Upvotes: 0

Views: 70

Answers (4)

Ashish Charan
Ashish Charan

Reputation: 2387

MVC firstly stands for Model View Controller.

Controllers

Controllers are nothing but classes which inherit from Controller base class and have different functions. For example:

public class SchoolController : Controller
{
 public SomeReturnType AllStudents
 {
   // Return all students
 }

 // More Functions here...
}

And these functions are responsible for providing response to the client request. When a client tries to open a URL (www.example.com/School/AllStudents) - MVC does mapping to Controller Class SchoolController and then to the method AllStudents

Models

Now models are again classes. Models represent your database tables. So for example, if you have a student table in SQL then we will have Student Model in MVC. Example:

public Class Student
{
public int StudentId{get;set;}
public string Name {get;set;}
public DateTime DOB{get;set;}
}

Now in order to bring data from the database and put into our model, we use EntityFramework. So entity framework connects to the database and puts the data from the database table into our model.

Views

Now understand as I said earlier controller action will get called on client request. Now It is the duty of controller action(function) to provide response to the client requests. Now When the client requests for School/AllStudents, I can return it a simple list of strings, and it will get displayed on browser in the raw form. i.e. No formatting just the plain data. Now obviously we would not do that, instead I will make a good HTML page with the List of students and then send to the client.

So here comes Views in the picture. Views are simply HTML templates. In which you fill your data and return to the client.

In my mind I think of MVC as a routing mechanism.

To proceed further on learning MVC i would advise you to brush up your basic concepts on:

  1. LINQ
  2. Lambda Functions
  3. Extension methods
  4. Anonymous Types

These concepts are used everywhere in MVC.

Good Luck!

Upvotes: 0

francorobles
francorobles

Reputation: 41

This is the best site to go. http://www.asp.net/mvc

For me if you want full control and testable web app without having to worry on the UI, I would use MVC. Everyone is going to this route. And so am I. =)

Upvotes: 0

Rami
Rami

Reputation: 7290

Have a look at this article from CodeProject. It explains the MVC using a simple C# WinForms application.

http://www.codeproject.com/Articles/383153/The-Model-View-Controller-MVC-Pattern-with-Csharp

Upvotes: 0

Mark
Mark

Reputation: 2504

No short sweet answer here will give it full justice, please have a look at this article.

wiki Model View Controller

or maybe even this

https://softwareengineering.stackexchange.com/questions/127624/what-is-mvc-really

As for the implementation of the pattern it will depend entirely on what your using to program with. I would advise search for mvc in the language or technology of your choice and follow a few examples, then get started once you understand the concepts of MVC

Upvotes: 1

Related Questions