• USA : +1 973 910 5725
  • INDIA: +91 905 291 3388
  • info@tekslate.com
  • Login

MVC Models

How to work with MVC models with an example

Create a new MVC2 application with the name “examples”;

Go to solution explorer

       ↓

Select the models folder

       ↓

Click with RM button

       ↓

Click on add

       ↓

Click on new item

       ↓

Select data option from visual C# in installed template

       ↓

S elect entity data model

       ↓

Type the EDM name (employee.EOMX)

       ↓

Click on add

       ↓

Select the option generate from data base

       ↓

Click on next

       ↓

Click on new connection

       ↓

Type the server name (“dot net” or satya)

       ↓

Activate the radio button

       ↓

Use SQL authentication

       ↓

–> Type username (“Sa”);

       ↓

Type password (“ABC”);

       ↓

Select the D/B as employee

       ↓

Click on ok

       ↓

Active the radio button  –> yes includes the sensitive data in the connection string

       ↓

Connection string name you find as employee entity

       ↓

Click on next

 

This will retrieve complete D/B objects and

       ↓

From select emp details table

       ↓

Click on finish

  1. Employee entities
  2. Emp details

The model for data is ready

Learn the core features of ASP.NET Training and become master with our expertise tutorials.

Creation action method in control class

       ↓

Go to home controller.cs file

       ↓

Write the following code

Using examples models; 2 name space

Public action result sample data ()

{

Employee entities.obj=new employee entities ();

View data [“Emp”] = obj.Emp details to list();

Return views ();

}

 

Creating view:

Go to home folder;

       ↓

Add new view page (sample data)

       ↓

Write the following code

<%@ import name space = “examples.models”%>

<body>

<h1>welcome to satya</h1>

<div>

<table align = “center” border = “2”>

<tr>

<th>Emp id </th><th>Ename</th><th>Designation</th><th>DOJ</th><th>salary</th><th>Deptno</th>

</tr>

 

<% for each (var x in (Enumerable<Emp class detail>) view data [“Emp”]

{                                                                                                                               //  C# code

%>

<tr>

<td><%=HTML.Encode(x.Emp Id)%></td>

<td><%=HTML.Encode(x.Ename)%></td>

<td><%=HTML.Encode(x.designation)%></td>

<td><%=HTML.Encode(DOJ)%></td>                          // MVC code 

</tr>

 

<%}%>        //C# code

</table>

</div>

</body>

Run the application and check

For indepth understanding click on

 

Summary
Review Date
Reviewed Item
MVC Models
Author Rating
5

“At TekSlate, we are trying to create high quality tutorials and articles, if you think any information is incorrect or want to add anything to the article, please feel free to get in touch with us at info@tekslate.com, we will update the article in 24 hours.”

0 Responses on MVC Models"

Leave a Message

Your email address will not be published. Required fields are marked *

Site Disclaimer, Copyright © 2016 - All Rights Reserved.