我正在使用Asp.net MVC5,并且自从使用Microsoft MVC平台4年以来没有遇到过这样的模糊错误!默认MVC5模板中的管理页面中发生错误。这里第26行位于_layout.cshtml
文件:
Line 24: <![endif]-->
Line 25:
Line 26: @Scripts.Render("~/js/intf")
Line 27: <script>
Line 28: if (document.documentMode === 10) {
Stack Trace说:
[NullReferenceException:对象引用未设置为的实例 对象。] ASP._Page_Views_Shared__Layout_cshtml.Execute()in c:\ Users \ fake \ Documents \ Visual Studio 2013 \项目\用户名\用户名\查看\ Shared_Layout.cshtml:26
System.Web.WebPages.WebPageBase.ExecutePageHierarchy()+198
System.Web.Mvc.WebViewPage.ExecutePageHierarchy()+104
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext,TextWriter writer,WebPageRenderingBase startPage)+90
System.Web.WebPages&LT;&GT; c__DisplayClass7.b__6(TextWriter的 编者)+232 System.Web.WebPages.HelperResult.WriteTo(TextWriter 编者)+10 System.Web.WebPages.WebPageBase.Write(HelperResult 结果)+80
System.Web.WebPages.WebPageBase.RenderSurrounding(字符串 partialViewName,Action1 body) +63
1 filters,Int32 filterIndex,ResultExecutingContext preContext, ControllerContext controllerContext,ActionResult actionResult)+56
System.Web.WebPages.WebPageBase.PopContext() +267
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +98
System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +235
System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +107
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +291 System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420
1个过滤器,ActionResult actionResult)+52
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList
System.Web.Mvc.Async&LT;&GT; c__DisplayClass28.b__19() +173 System.Web.Mvc.Async。&lt;&gt; c__DisplayClass1e.b__1b(IAsyncResult) asyncResult)+100
System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +10
1.End()+49
System.Web.Mvc.Async.WrappedAsyncResultBase
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult的 asyncResult)+27
System.Web.Mvc.Controller.b__1d(IAsyncResult的 asyncResult,ExecuteCoreState innerState)+13
System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +36
1.End()+54
System.Web.Mvc.Async.WrappedAsyncResultBase
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)+39 System.Web.Mvc.Controller.b__15(IAsyncResult的 asyncResult,控制器控制器)+12
System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +28
1.End()+54
System.Web.Mvc.Async.WrappedAsyncResultBase
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)+29
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult的 asyncResult)+10
System.Web.Mvc.MvcHandler.b__4(IAsyncResult的 asyncResult,ProcessRequestState innerState)+21
System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +36
1.End()+54
System.Web.Mvc.Async.WrappedAsyncResultBase
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +31 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult) 结果)+9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9688704 System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean&amp; completedSynchronously)+155
修改: 正如您想要的捆绑代码一样,我将其中一个放在这里:
bundles.Add(new ScriptBundle("~/js/intf").Include(//first internal scripts
"~/js/jquery*",
"~/js/modernizr.js",
"~/js/ie-prototype-polyfill.js",
"~/js/prettyPhoto.js"));
注意:如果我认为错误行(样式/脚本捆绑行)错误将@ViewBag.Title
作为新错误!我认为Razor视图引擎在这里遇到麻烦,因为它无法实例化视图的代码要求,但为什么?
我知道使用Microsoft技术时出现的一些错误并不是与它所说的错误有关。请给我留下你的有益经验。感谢。
更新:
~/views/Account/Manage.cshtml
文件的简洁内容可能很有用:
@using Social.Models;
@using Microsoft.AspNet.Identity;
@{
ViewBag.Title = "manage";
}
<div class="layout-app">
<div class="row row-app margin-none">
<div class="col-md-12">
@if (ViewBag.HasLocalPassword)
{
@Html.Partial("_ChangePasswordPartial")
}
else
{
@Html.Partial("_SetPasswordPartial")
}
</div>
</div>
</div>
答案 0 :(得分:4)
由于我在主布局文件中使用ViewBag
作为显示项目页面的必需变量,缺少初始化导致我出现这样的错误!这是我迄今为止从微软开发技术中看到的无关错误之一。
答案 1 :(得分:-1)
尝试在MVC解决方案中的文件夹Scripts中创建一个新的javascript文件,并调用app.js文件(或其他任何内容)。
然后将以下行放在其他@ scripts.Render行下面以运行它。
<script src="@Scripts.Url("~/Scripts/app.js")"></script>
否则将文件添加到包中。