故障我只是得到了一些錯誤,我不希望看到你...Razor視圖 - 第
要清楚,我會告訴工作代碼和代碼錯誤:
這是工作
_MainLayout.cshtml
<div id="content">
<h1>@Page.Title</h1>
@RenderSection("left", false)
@RenderBody()
</div>
Page.cshtml
@section left{
<p>Some text on left side</p>
}
<div>
Some content
</div>
在這種情況下,一切工作正常,但當我刪除@RenderSection("left", false)
裏面_MainLayout.cshtml
我得到異常!我需要哪種情況?見下面的例子:
這不是工作
_MainLayout.cshtml
@if (WebSecurity.IsAuthenticated) {
<h1>@Page.Title</h1>
@RenderSection("left", false)
@RenderBody()
} else {
<h1>You not logged in!</h1>
<p>To see this page, you have to login first.</p>
}
Page.cshtml
@section left{
<p>Some text on left side</p>
}
<div>
Some content
</div>
在這種情況下,如果用戶沒有通過驗證,我有這樣的例外:
描述:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
異常詳細信息:System.Web.HttpException: Следующие разделы были определены, но не были обработаны для страницы макета "~/_MainLayout.cshtml": "left".
可以翻譯爲:Section was created but wasn't rendered for layout page "~/_MainLayout.cshtml": "left".
源錯誤:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
堆棧跟蹤:
[HttpException (0x80004005): Следующие разделы были определены, но не были обработаны для страницы макета "~/_MainLayout.cshtml": "left".]
System.Web.WebPages.WebPageBase.VerifyRenderedBodyOrSections() +91298
System.Web.WebPages.WebPageBase.PopContext() +332
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +95
System.Web.WebPages.<>c__DisplayClass7.<RenderPageCore>b__6(TextWriter writer) +102
System.Web.WebPages.HelperResult.WriteTo(TextWriter writer) +12
System.Web.WebPages.WebPageBase.Write(HelperResult result) +67
System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action`1 body) +66
System.Web.WebPages.WebPageBase.PopContext() +262
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +95
System.Web.WebPages.WebPageHttpHandler.ProcessRequestInternal(HttpContext context) +249
問題是:我該如何使它工作? 任何建議是有價值的!
這很有趣,但我沒有使用MVC。 (我只是玩WebMatrix,並試圖實現我的想法)這就是爲什麼處理每個頁面上的安全性是一種愚蠢的......但我會嘗試重新定向到錯誤頁面。也許它會工作。謝謝你在這裏指出我;) – RAMe0 2011-01-25 02:27:10