我想在我的應用程序中使用2個獨立的佈局。假設一個用於網站的公開部分,另一個則由於我們需要的某些原因而爲空。如何在ASP.NET Core MVC中指定不同的佈局
核心之前,我可以做這個定義過濾器:
public class LayoutInjecterAttribute : ActionFilterAttribute
{
private readonly string _masterName;
public LayoutInjecterAttribute(string masterName)
{
_masterName = masterName;
}
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
base.OnActionExecuted(filterContext);
var result = filterContext.Result as ViewResult;
if (result != null)
{
result.MasterName = _masterName;
}
}
}
現在的ViewResult沒有MasterName財產。是否可以現在做,而不是在查看佈局定義中使用。
日Thnx
Thx,但這並不是我所期待的。但有趣的想法。 – Wasyster