我的应用正在产生错误
未将对象引用设置为对象的实例。
由于某些原因,Postal在根_ViewStart.cshtml中给出了布局错误,特别是第一个if语句,如下所示。
_ViewStart.cshtml
if (this.User.IsInRole("Admin") || !this.User.Identity.IsAuthenticated)
{
Layout = "~/Views/Shared/_Layout.cshtml";
}
else if (this.User.IsInRole("Territorial Strategic Planning Coordinator") || this.User.IsInRole("Programme Secretary") || this.User.IsInRole("IT") || !this.User.Identity.IsAuthenticated)
{
Layout = "~/Views/Shared/_LayoutLevel1.cshtml";
}
else if (this.User.IsInRole("Divison Commander") || !this.User.Identity.IsAuthenticated)
{
Layout = "~/Views/Shared/_LayoutLevel2.cshtml";
}
else if (this.User.IsInRole("Corps Officer") || this.User.IsInRole("Centre Admin") || !this.User.Identity.IsAuthenticated)
{
Layout = "~/Views/Shared/_LayoutLevel3.cshtml";
}
我在控制器中使用的代码是:
dynamic email = new Email("GoalNotification");
email.ResponseID = goal.ResponseID;
email.User = user.UserName;
email.To = user.Email;
email.Send();
和邮政视图是: 的 GoalNotification.cshtml
To: @ViewBag.To
Subject: Goal Notification for Response : @ViewBag.ResponseID
<div>
<p style="font-size:large; font-weight:bold">
Dear @ViewBag.User
</p>
<p>
This is a system generated notification to notify you that one or more of your goals need attention.
</p>
<p>
Please revise and re-submit.
</p>
<p>Kind Regards</p>
<p>TSP</p>
----------------------------------------------------------------------------------
<p style="font-weight:100"><u>Contact Details</u></p>
<p>Office Number: </p>
<p>Email Address: </p>
<p>Physical Address: </p>
<hr />
</div>
我在这里做错了吗?有什么办法可以解决这个问题吗? 这是我第一次使用Postal。谢谢你的帮助。
编辑:我只得到这个错误,因为MVC Postal似乎覆盖了我的根_ViewStart。没有它,该程序正常运行。
如果指定了多个布局,则邮件会出现问题。如果我有一套布局,它的工作原理。不幸的是我需要它们。
堆栈跟踪:
[NullReferenceException: Object reference not set to an instance of an object.]
ASP._Page_Views__ViewStart_cshtml.Execute() in c:\Users\Shahil\Desktop\TSPMVC Backups\2016\28-01-2016\TSP MVC\TSP MVC\Views\_ViewStart.cshtml:3
System.Web.WebPages.StartPage.ExecutePageHierarchy() +73
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +131
System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +695
System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +382
Postal.EmailViewRenderer.RenderView(IView view, ViewDataDictionary viewData, ControllerContext controllerContext, ImageEmbedder imageEmbedder) +182
Postal.EmailViewRenderer.Render(Email email, String viewName) +204
Postal.EmailService.CreateMailMessage(Email email) +72
Postal.EmailService.Send(Email email) +65
Postal.Email.Send() +56
CallSite.Target(Closure , CallSite , Object ) +189
System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid1(CallSite site, T0 arg0) +432
TSP_MVC.Controllers.GoalsController.AdminEdit(Goal goal) in c:\Users\Shahil\Desktop\TSPMVC Backups\2016\28-01-2016\TSP MVC\TSP MVC\Controllers\GoalsController.cs:195
lambda_method(Closure , ControllerBase , Object[] ) +180
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +59
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +435
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +60
System.Web.Mvc.Async.ActionInvocation.InvokeSynchronousActionMethod() +76
System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +36
System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) +73
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +136
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +102
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +49
System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() +117
System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +323
System.Web.Mvc.Async.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) +44
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +47
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +136
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +102
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +50
System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +72
System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +185
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +133
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +40
System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +34
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +133
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +37
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +44
System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +39
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +62
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +133
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +37
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +39
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +39
System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +39
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +133
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +37
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +40
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9721605
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155