码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2016-09-30 14:59:09      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:

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>15000)
 {
     <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 = 20000;           
 return View("MyView",emp);

 

 

 

 

 

 

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

标签:

原文地址:http://www.cnblogs.com/volts0302/p/5923512.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!