查了一上午资料,找到了一种比较有效的方法

后台控制器:public ActionResult Index()  

{  

    List<string> colors = new List<string>();  

    colors.Add("red");  

    colors.Add("green");  

    colors.Add("blue");  

    ViewData["listColors"] = colors;

 return View();  

}  

前台界面:

 @foreach (var color in ViewData["listColors"] as List<string>)  

    {

 @color  

    }  

我认为这种比较清楚简单。

还有其他几种传值方式(View和Action之间的数据传输)

ViewBag动态型

后台控制器:public ActionResult Index()  

{  

    

  Dictionary<string, string> stackholder = new Dictionary<string, string>();
    stackholder.Add("Client", "Mr.  Client");
    stackholder.Add("Manager", "Mr. Joy");
    stackholder.Add("Team Leader", "Mr.Toy");
    stackholder.Add("Sr. developer", "Mr.dojoy");
    stackholder.Add("developer", "Mr. nodoy");
    ViewBag.stackholder = stackholder;

 return View();  

}  

前台界面:

 @ViewBag.stackholder

 

ViewData弱态型

Model动态类型

  后台:return View(data)//相当于存入ViewData.Model

    前台:Model

 

相关文章:

  • 2021-11-18
  • 2021-11-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-16
  • 2022-03-13
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-20
  • 2022-12-23
  • 2022-12-23
  • 2021-12-10
相关资源
相似解决方案