KNOWLEDGE BASE

Umbraco 7 Template View Is Deleted When Saving Through the Backoffice Umbraco Dashboard


When logged in to the Umbraco backoffice control panel, you attempt to make a change to a template and click the "Save" button, but doing so causes the MVC Razor Layout template file to be deleted.  It still shows up in the template tree in the "Settings" dashboard of the Umbraco control panel, but no longer exists in the file system of the server.

When saving a view in Umbraco, the file is deleted, accessing a page that inherits from this view gives the following exception:

Server Error in '/' Application.

The layout page "~/Views/<Global.cshtml>" could not be found at the following path: "~/Views/<Global.cshtml>".
Description: 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.
Exception Details: System.Web.HttpException: The layout page "~/Views/Global.cshtml" could not be found at the following path: "~/Views/Global.cshtml".

Source Error:

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.

Stack Trace:
[HttpException (0x80004005): The layout page "~/Views/Global.cshtml" could not be found at the following path: "~/Views/Global.cshtml".] System.Web.WebPages.WebPageBase.PopContext() +306704 Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer) +140 System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +380 System.Web.Mvc.<>c__DisplayClass1a.b__17() +33 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +613 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +613 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +263 System.Web.Mvc.Async.<>c__DisplayClass25.b__22(IAsyncResult asyncResult) +240 System.Web.Mvc.<>c__DisplayClass1d.b__18(IAsyncResult asyncResult) +28 System.Web.Mvc.Async.<>c__DisplayClass4.b__3(IAsyncResult ar) +15 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53 System.Web.Mvc.Async.<>c__DisplayClass4.b__3(IAsyncResult ar) +15 System.Web.Mvc.<>c__DisplayClass8.b__3(IAsyncResult asyncResult) +42 System.Web.Mvc.Async.<>c__DisplayClass4.b__3(IAsyncResult ar) +15 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288 Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34248

This issue is caused by including ASP.NET Masterpage controls that use the runat="server" directive in the view. Please note: this happens even if the element itself is commented out, as shown in the following code snippet:

@* <asp:Literal ID="MyLiteral" runat="server" text="some string"/> *@

To resolve this problem, ensure that all ASP.NET components are removed from the MVC Razor view template (including those that are commented out!)

 


Speak to Simon Steed about any of the topics discussed this site.


Need an Umbraco Master?

Here at Simon Antony, we have an in house certified Umbraco Grand Master available for hire. Got a problem with your site, need architecture advice, give us a call to speak to Simon directly and see how we can help

Contact Simon Today!