Week 2 Lecture 4 Lab
Week 2 Lecture 4 Lab
Net MVC
Course Code: CSC 4164 Course Title: ADVANCED PROGRAMMING WITH .NET
• Business/domain logic
• Model objects, retrieve and store model state in a persistent storage (database).
public class Customer{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Company { get; set; }
public IEnumerable Orders { get; set; }
}
Creating Models
Add a folder named “Models”. In Solution Explorer, right-click the project. Select Add
New Folder. Name the folder Models.
Right-click the Models folder and select Add New Item. In Add New Item, select the
Class. Name the class TodoItem and click OK.
publicclassTodoItem
{
public string Key { get; set; }
public string Name { get; set; }
public bool IsComplete { get; set; }
}
Strongly typed views
• The view which binds to a specific type of View Model by passing the model
object as a parameter to the View() method is called as Strongly Typed View.
return View(employee);
}
}
Changes in Index.cshtml View:
@model FirstMVCDemo.Models.Employee
<!DOCTYPE html>
<html> Advantages of Strongly-typed views:
<head> • Strongly Typed View in ASP.NET MVC
<meta name="viewport" provides compile-time error checking as
content="width=device-width" /> well as intelligence support.
<title>Page Title</title> • If we misspell the property name, then
</head> it comes to know at compile time rather
<body> than at runtime.
<h2>@ViewBag.Header</h2>
<table style="font-family:Arial">
<tr>
<td>Employee ID:</td>
<td>@Model.EmployeeId </td>
</tr>
<tr>
<td>Name:</td>
<td>@Model.Name</td>
</tr> </table>
</body>
</html>
Books