예제 #1
0
        private void GetHtml(IViewEngine viewEngine, string viewName, string controllerName, object model, string userId)
        {
            if (!viewName.Contains("/"))
            {
                viewName = controllerName + "/" + viewName;
            }

            var(viewPath, viewExists) = FindView(viewName);

            if (!viewExists)
            {
                this.MissingViewError(viewPath);

                return;
            }

            var viewContent = File.ReadAllText(viewPath);

            var(layoutPath, layoutExists) = FindLayout();

            if (layoutExists)
            {
                var layoutContent = File.ReadAllText(layoutPath);

                viewContent = layoutContent.Replace("@RenderBody()", viewContent);
            }


            viewContent = viewEngine.RenderHtml(viewContent, model, userId);

            this.SetContent(viewContent, HttpContentType.Html);
        }
예제 #2
0
        private void GetHtml(IViewEngine viewEngine, string viewName, string controllerName, object model, string userId)
        {
            if (!viewName.Contains(PathSeparator))
            {
                viewName = controllerName + PathSeparator + viewName;
            }

            var viewPath = Path.GetFullPath($"./Views/" + viewName.TrimStart(PathSeparator) + ".cshtml");

            if (!File.Exists(viewPath))
            {
                this.PrepareMissingViewError(viewPath);

                return;
            }

            var viewContent = File.ReadAllText(viewPath);

            var layoutPath = Path.GetFullPath("./Views/Layout.cshtml");

            if (File.Exists(layoutPath))
            {
                var layoutContent = File.ReadAllText(layoutPath);

                viewContent = layoutContent.Replace("@RenderBody()", viewContent);
            }

            if (model != null)
            {
                viewContent = viewEngine.RenderHtml(viewContent, model, userId);
            }

            this.SetContent(viewContent, HttpContentType.Html);
        }