我有一個母版稱爲_Layout.cshtml
並放置在文件夾Views/Shared/_Layout.cshtml
英寸 我創建了一個控制器:SharedController.cs
將數據傳遞到_Layout.cshtml
但不會進入控制器。 如何將數據傳遞給每個加載主頁_Layout.cshtml
?MVC 4主頁_layout傳遞數據
例如,這是控制器:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace HAnnoZero.Controllers
{
public class SharedController : Controller
{
public ActionResult _Layout()
{
ViewBag.help = "ciao";
return View();
}
}
}
你到底做_layout是,母版頁,我不認爲你可以這樣做 –
在母版頁我有一個菜單,在這個菜單中,我想插入標籤,顯示方法計數從db – ADC
在動作中使用viewbag或在主佈局中編寫代碼 –