コード例 #1
0
        protected HttpResponse View(
            object viewModel = null,
            [CallerMemberName] string viewPath = null)
        {
            var viewContent = File.ReadAllText(
                "Views/" +
                GetType().Name.Replace("Controller", string.Empty) +
                "/" + viewPath + ".html");

            IdentityUser user = GetUser();

            viewContent = viewEngine.GetHtml(viewContent, viewModel, user);

            var responseHtml = PutViewInLayout(viewContent, user, viewModel);

            var response = new HtmlResult(responseHtml, HttpResponseStatusCode.Ok);

            return(response);
        }
コード例 #2
0
        protected IActionResult View <T>(T model = null, [CallerMemberName] string viewName = null) where T : class
        {
            string controllerName = this.GetType().Name.Replace("Controller", "");
            string path           = $"Views/{controllerName}/{viewName}.html";
            string viewContent    = System.IO.File.ReadAllText(path);
            string layoutView     = System.IO.File.ReadAllText($"Views/{GlobalConstants.LayoutName}");
            string view           = layoutView.Replace("@RenderBody()", viewContent);

            view = viewEngine.GetHtml <T>(view, model, this.ModelState, this.User);

            return(new HtmlResult(view, HttpResponseStatusCode.Ok));
        }