0

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

4

1 回答 1

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
于 2013-11-21T13:54:17.833 回答