我必須在MVC視圖中打印/顯示少量變量的值。我怎樣才能做到這一點..在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'到視圖並迭代它?或者可能使用反射和自動化過程(假設你只是從'ViewBag'剝離屬性) –
2011-12-19 14:34:52
,你可以顯示你的視圖定義? – 2011-12-19 14:35:03
請看下面我的回答..謝謝 – ZVenue 2011-12-19 14:54:10