MVC中Control和View之间数据传递的方式

1:ViewBag和ViewData

具体区别不做讨论,本处只演示ViewData的具体示例:

Controler代码:ViewData["Employee"] = emp;

View代码:

      @{
WebApplication1.Models.Employee emp=(WebApplication1.Models.Employee)
ViewData["Employee"];
} <b>Employee Details </b><br />
Employee Name : @emp.FirstName@emp.LastName <br />
Employee Salary: @emp.Salary.ToString("C")
</div>

  2:强类型

前台:@model WebApplication1.Models.Employee

@Model.FirstName @Model.LastName
@if(Model.Salary>)
{
<span style="background-color:yellow">
Employee Salary: @Model.Salary.ToString("C")
</span>
}

后台Controler代码:

 Employee emp = new Employee();
emp.FirstName = "Sukesh";
emp.LastName="Marla";
emp.Salary = ;
return View("MyView",emp);
上一篇:windows下一个erlang包装镜像启动


下一篇:《重构-改善既有代码的设计》学习笔记---Replace Temp with Query(以查询取代临时变量)