【发布时间】:2011-12-19 14:30:47
【问题描述】:
我必须在 MVC 视图中打印/显示几个变量的值。我该怎么做..
public ActionResult DisplayVariables()
{
ViewBag.Message = "Welcome to ASP.NET MVC!";
{
//After some process/logic.. variables get assigned values here..
int var1 = xxxxxx;
int var2 = xxxxx;
int var3 = xxxxxx;
int var4 = xxxxx;
}
return View() //I want to display variables values with lables here in this
//view. I already have a view with name "DisplayVariables"
}
【问题讨论】:
-
向视图发送
Dictionary<String,Object>并对其进行迭代?或者可能使用反射并使过程自动化(假设您只是从ViewBag中剥离属性) -
你能显示你的视图定义吗?
-
请看下面我的回答..谢谢
标签: asp.net-mvc asp.net-mvc-3 view