Exemple #1
0
        /// <summary>
        /// Manages script separation of concerns convention by loading the different javascript portions of each partial into a context item.
        /// </summary>
        private void RegisterJavaScript(ControllerContext controllerContext, string viewPath)
        {
            Guid?guid = null;
            ExtendedControllerContext extendedContext = GetExtendedControllerContext(controllerContext);

            if (extendedContext != null)
            {
                // When we render the view, we add JavaScript to the provided context, we identify contexts by using Guids.
                guid = extendedContext.Guid;
            }
            StringRenderingController controller = controllerContext.Controller as StringRenderingController;

            if (controller == null)
            {
                throw new InvalidOperationException(Resources.Error.ControllerBaseTypeMismatch);
            }
            if (viewPath.EndsWith(Resources.Constants.JavaScriptViewNamingExtension)) // sanity.
            {
                return;                                                               // prevent StackOverflowException.
            }
            string partial = controller.JavaScriptPartialViewString(viewPath, controller.ViewData.Model);

            if (partial != null)
            {
                IJavaScriptHelper javaScriptHelper = kernel.Resolve <IJavaScriptHelper>();
                javaScriptHelper.Register(viewPath, partial, guid);
            }
        }
Exemple #2
0
 private void WriteViewResponse(Exception exception, StringRenderingController controller)
 {
     if (!WriteJsonResponse(controller.Request, controller.Response, User.UnhandledExceptionJson))
     {
         HttpResponseBase response = controller.Response;
         ErrorViewModel   model    = helper.GetErrorViewModel(controller.RouteData, exception);
         string           result   = controller.ViewString(Constants.ErrorViewName, model);
         response.ContentType = Constants.HtmlContentType;
         response.Write(result);
     }
 }