在Razor View中添加两个ViewData变量

时间:2013-11-21 13:42:32

标签: asp.net asp.net-mvc-4 razor razorengine

我是ASP新手。 我想知道我可以在ViewData Razor视图中添加两个ASP.net MVC4变量,该变量是从控制器传递的吗?

1 个答案:

答案 0 :(得分:0)

以下是您的示例代码

public ActionResult Detail(int id)
{

  Model model=Repository.Find(id);
  ViewData["key1"]="some data";
  ViewData["key2"]="some other data";3
  //or using ViewBag (dynamic type)
  ViewBag.key1="some data";
  ViewBag.key2="some other data";

  return View(model);

}

在视图页面

@ViewData["key1"]

@ViewBag.key1