我是ASP新手。
我想知道我可以在ViewData
Razor
视图中添加两个ASP.net MVC4
变量,该变量是从控制器传递的吗?
答案 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