294,852 views 175 on YTPak
559 26

Published on 10 May 2013 | over 5 years ago

Text version of the video


All ASP .NET MVC Text Articles

All ASP .NET MVC Slides

All Dot Net and SQL Server Tutorials in English

All Dot Net and SQL Server Tutorials in Arabic

In this video, we will discuss using business objects as model. Until now, we have been using entity framework and entities. Entities are mapped to database tables, and object relational mapping tools like Entity Framework, nHibernate, etc are used to retrieve and save data. Business objects contain both state(data) and behaviour, that is logic specific to the business.

In MVC there are several conventions that needs to be followed. For example, controllers need to have the word controller in them and should implement IController interface either directly or indirectly. Views should be placed in a specific location that MVC can find them.

The following URL will invoke Index() action method with in the HomeController. Notice that our HomeController inherits from base Controller class which inturn inherits from ControllerBase class. ControllerBase inturn inherits from IController class.

return View() statement with in the HomeController by default looks for a view with name = "Index" in "/Views/Home/" and "/Views/Shared/" folders. If a view with name = "Index" is not found, then, we get an error

But with models, there are no strict rules. Infact "Models" folder is optional and they can live anywhere. They can even be present in a separate project.

Let's now turn our attention to using business objects as model.

Stored procedure to retrieve data
Create procedure spGetAllEmployees
Select Id, Name, Gender, City, DateOfBirth
from tblEmployee

Step 1: Create an ASP.NET MVC 4 Web application with name = MVCDemo

Step 2: Add a Class Library project with Name="BusinessLayer"

Step 3: Right click on the BusinessLayer class library project, and add a class file with name = Employee.cs.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BusinessLayer
public class Employee
public int ID { get; set; }
public string Name { get; set; }
public string Gender { get; set; }
public string City { get; set; }
public DateTime DateOfBirth { get; set; }

Step 4: Right click on the "References" folder of the "BusinessLayer" class library project, and add a reference to "System.Configuration" assembly.

Step 5: Right click on the BusinessLayer class library project, and add a class file with name = EmployeeBusinessLayer.cs.

Step 6: Right click on the "References" folder of the "MVCDemo" project, and add a reference to "BusinessLayer" project.

Step 7: Include a connection string with name = "DBCS" in Web.Config file

Step 8: Right click on the "Controllers" folder and add Controller with name = "EmployeeController.cs".

Step 9: Right click on the Index() action method in the "EmployeeController" class and select "Add View" from the context menu. Set
View name = Index
View engine = Razor
Select "Create a strongly-typed view" checkbox
Scaffold Template = List
Click "Add" button

Run the application.
Customize Your Hybrid Embed Video Player!

6-digit hexadecimal color code without # symbol.


Report video function is under development.


Loading related videos...