static void Main(string[] args)
        {
            //this is required because the IHostingEnvironment needs to be initialized with this assembly name
            RazorViewRenderer.Initialize(Assembly.GetExecutingAssembly());

            //this will compile the test view in this project and display it
            Console.Write(RazorViewRenderer.RenderView("Views/TestView.cshtml"));

            //this will run the precompiled view in the razor library
            Console.Write(RazorViewRenderer.RenderView("Views/TestView2.cshtml"));

            Console.ReadKey();
        }
        public static IActionResult Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("Rendering local view from project folder.");

            //this is required because the IHostingEnvironment needs to be initialized with this assembly name
            RazorViewRenderer.Initialize(Assembly.GetExecutingAssembly());

            //This will fail, the view will not compile correctly on functions
            var view = RazorViewRenderer.RenderView("Views/TestView.cshtml");

            return(new OkObjectResult(view));
        }
Exemple #3
0
        public static IActionResult Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("Rendering precompiled view from class library.");

            //this is required because the IHostingEnvironment needs to be initialized with this assembly name
            RazorViewRenderer.Initialize(Assembly.GetExecutingAssembly());

            //This will fail if you haven't views dll manually into the bin folder
            var view = RazorViewRenderer.RenderView("Views/TestView2.cshtml");


            return(new OkObjectResult(view));
        }
Exemple #4
0
        public HttpResponseMessage RenderHTMLByRazor()
        {
            var model = new SampleModel
            {
                FirstName = "John",
                LastName  = "Doe"
            };

            var sDocument = RazorViewRenderer.RenderView("~/views/Sample.cshtml", model);

            var response = new HttpResponseMessage();

            response.Content = new StringContent(sDocument);
            response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");
            return(response);
        }