Controller中的代碼如下var bingo = new Web1.Models.Bingo() { Title = "測試", desc = "嘻嘻", StarTime = DateTime.Now, EndTime = DateTime.Now.... ...
Controller中的代碼如下
var bingo = new Web1.Models.Bingo() { Title = "測試", desc = "嘻嘻", StarTime = DateTime.Now, EndTime = DateTime.Now.AddDays(7), startPrice = 100, currentPrice = null };
如何將bingo傳到view中進行調用呢,大致有如下:
- Controller使用 ViewData,代碼如下
ViewData["abingo"] = bingo;
調用
@{ var bingo =ViewData["abingo"] as Web1.Models.Bingo; }
或者viewbag對象,就可以在view里就可以使用對象了
@{ var bingo = ViewBag.bingo; }
2.在Controller中直接將對象傳給view
return View(bingo);
//原來是return View();
然後在view裡面調用如下代碼即可
@{ var bingo = Model; }
寫成 下麵的內容,則model的引用都會變為類實例的強引用
@model Web1.Models.Bingo @{ var bingo = Model; }