I'm new to MVC. Trying to load a partial view but get a 500 error in browser console.
After clicking on submit, the action method is triggered and the code is executed without any errors.
I would like to replace the content of myform
with a partial view, but there is an error in the browser console.
Do I need to configure any routes. If so, please tell me what/how it should be.
Using Sitecore 8.0.
main.cshtml
<div id="myform">
@using (Ajax.BeginForm("ResetPassword", "Member", new AjaxOptions { UpdateTargetId = "myform", InsertionMode = InsertionMode.Replace }))
{
.....
<input type="submit" value="Submit"/>
}
</div>
controller
[HttpPost]
public ActionResult ResetPassword()
{
....
return PartialView("~/Views/success.cshtml");
}
success.cshtml
@
{
var contextItem = Sitecore.Context.Item;
}
<div>
<h3>Your password has been updated.</h3>
<p>@contextItem.Fields[<id>].Value</p>
</div>
Error:
POST http://mysite.org/api/sitecore/Member/ResetPassword 500 (Internal Server Error)
Stack Trace
> 25812 19:45:17 ERROR Application error. Exception:
> System.Web.HttpUnhandledException Message: An unhandled exception
> occurred. Source: Sitecore.Mvc at
> Sitecore.Mvc.Pipelines.MvcEvents.Exception.ShowAspNetErrorMessage.ShowErrorMessage(ExceptionContext
> exceptionContext, ExceptionArgs args) at
> Sitecore.Mvc.Pipelines.MvcEvents.Exception.ShowAspNetErrorMessage.Process(ExceptionArgs
> args) at (Object , Object[] ) at
> Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) at
> Sitecore.Mvc.Pipelines.PipelineService.RunPipeline[TArgs](String
> pipelineName, TArgs args) at
> Sitecore.Mvc.Filters.PipelineBasedRequestFilter.OnException(ExceptionContext
> exceptionContext) at
> System.Web.Mvc.ControllerActionInvoker.InvokeExceptionFilters(ControllerContext
> controllerContext, IList`1 filters, Exception exception) at
> System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext
> controllerContext, String actionName) at
> Sitecore.Mvc.Controllers.SitecoreActionInvoker.InvokeAction(ControllerContext
> controllerContext, String actionName) at
> System.Web.Mvc.Controller.<>c__DisplayClass22.<BeginExecuteCore>b__1e()
> at System.Web.Mvc.Async.AsyncResultWrapper.<.cctor>b__0(IAsyncResult
> asyncResult, Action action) at
> System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)
> at
> System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult
> asyncResult) at System.Web.Mvc.Controller.EndExecute(IAsyncResult
> asyncResult) at
> System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult
> asyncResult, ProcessRequestState innerState) at
> System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult
> asyncResult) at
> System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
> at
> Sitecore.Mvc.Routing.RouteHttpHandler.EndProcessRequest(IAsyncResult
> result) at
> System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
> at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
> Boolean& completedSynchronously)
>
> Nested Exception
>
> Exception: System.NullReferenceException Message: Object reference not
> set to an instance of an object. Source: App_Web_fel0uk2b at
> ASP._Page_Views_ResetPassword_cshtml.Execute() in
> c:\inetpub\wwwroot\mysite.org\Website\Views\ResetPassword.cshtml:line
> 7 at System.Web.WebPages.WebPageBase.ExecutePageHierarchy() at
> System.Web.Mvc.WebViewPage.ExecutePageHierarchy() at
> System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext
> pageContext, TextWriter writer, WebPageRenderingBase startPage) at
> System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
> at
> System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1
> filters, Int32 filterIndex, ResultExecutingContext preContext,
> ControllerContext controllerContext, ActionResult actionResult) at
> System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1
> filters, Int32 filterIndex, ResultExecutingContext preContext,
> ControllerContext controllerContext, ActionResult actionResult) at
> System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1
> filters, Int32 filterIndex, ResultExecutingContext preContext,
> ControllerContext controllerContext, ActionResult actionResult) at
> System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext
> controllerContext, IList`1 filters, ActionResult actionResult) at
> System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext
> controllerContext, String actionName)
Execute
method code please since the error is occurring in this which seems to be triggered from line 7 in theResetPassword.cshtml
contextItem
in the partial view which is null. Is this by default, that in partial views, we cannot get the Sitecore Context Item? If so, then I have to create an exclusive model for this partial view.