Questions tagged [razorengine]

Antaris RazorEngine is a parsing engine that allows robust templates using Razor syntax.

The RazorEngine is a parsing engine that allows robust templates using syntax.

From the project web site:

Using the templating engine couldn't be easier, using a simple syntax, we can do the following:

string template = "Hello @Model.Name! Welcome to Razor!";
string result = Razor.Parse(template, new { Name = "World" });

The templating engine supports strict and anonymous types, as well as customised base templates, for instance:

Razor.SetTemplateBase(typeof(HtmlTemplateBase<>));

string template = 
@"<html>
  <head>
    <title>Hello @Model.Name</title>
  </head>
  <body>
    Email: @Html.TextBoxFor(m => m.Email)
  </body>
  </html>";

var model = new PageModel { Name = "World", Email = "someone@somewhere.com" };
string result = Razor.Parse(template, model);
571 questions
46
votes
4 answers

RazorEngine layouts

I am using the Razor engine https://github.com/Antaris/RazorEngine to parse the body of my email templates. Is it possible to define a layout and include other .cshtml files? for example a common header and a footer.
ministrymason
  • 1,783
  • 2
  • 20
  • 33
35
votes
8 answers

RazorEngine issues with @Html

I am using RazorEngine to render out some basic content (a very crude content management system). It works great until I include any @Html syntax into markup. If the markup contains an @html I get the following error: Unable to compile template.…
JamesStuddart
  • 2,581
  • 3
  • 27
  • 45
35
votes
2 answers

Server Cannot Append Header After HTTP headers have been sent Exception at @Html.AntiForgery

I'm developing an asp.net mvc 5 application in which I was trying to redirect to the ReturnUrl by applying the code below : [HttpPost] [AllowAnonymous] public ActionResult Login(UserLogin model, string returnUrl) { if (ModelState.IsValid) { …
Bilal Ahmed
  • 1,043
  • 4
  • 17
  • 32
28
votes
4 answers

RazorEngine: cannot use Html.Raw

using RazorEngine outside asp.net I'm experiencing this error when I try to write raw html by using @Html.Raw("html string here"): Unable to compile template. The name 'Html' does not exist in the current context Can you help me? Thanks!
ff8mania
  • 1,553
  • 3
  • 19
  • 28
22
votes
3 answers

Why is a "You'll need a new app to open this localhost" popup being displayed when debugging my asp.net core 2.0 app in Edge?

I'm simply entering "MyMessages/Index" after localhost:51531/ and this popup is being displayed. Seems super weird to me but probably something simple. So I try to navigate to localhost:51531/MyMessages/Index in Edge. The controller is public class…
22
votes
3 answers

How to make intellisense works with RazorEngine?

I am trying to configure RazorEngine so that intellisense works on views. I add RazorEngine and Microsoft.AspNet.Mvc using nuget. I create TestView.cshtml and declare @model MyModel but it says The name 'model' does not exist in the current context.…
Anonymous
  • 9,366
  • 22
  • 83
  • 133
21
votes
3 answers

RazorEngine vs RazorTemplates vs RazorMachine

Can someone explain what are the differences, pros/cons between RazorEngine RazorTemplates RazorMachine I need to pick one for email generation. The requirements are quite usual: fast, ease-of-use. It seems like all of them has all features I need…
Sergii
  • 562
  • 6
  • 17
19
votes
3 answers

RazorEngine string layouts and sections?

I use razor engine like this: public class EmailService : IService { private readonly ITemplateService templateService; public EmailService(ITemplateService templateService) { if (templateService == null) { …
bevacqua
  • 47,502
  • 56
  • 171
  • 285
17
votes
5 answers

How do you escape a '@' symbol within in a url with razor

I know this is probably going to be something very simple and it is like just a 'gotcha' that I have yet to get; however, I have been struggling with escaping the @ symbol in the following URL.
Sam
  • 895
  • 1
  • 8
  • 26
16
votes
2 answers

Razor engine cant find view

I'm trying to render a HTML from a view without using a web request. I need the HTML as a string, internally, I do not wish to serve it. The viewEngine.FindView() returns a viewEnineResult that shows no view was found. It shows to search locations…
Daarwin
  • 2,896
  • 7
  • 39
  • 69
15
votes
2 answers

Isolated RazorEngine failing to pass model to different AppDomain

When I render my template without the EditHistory member, this works. However, when I add that additional member that is within my application I get an exception Could not load file or assembly 'Models, Version=1.0.0.0, Culture=neutral,…
Sam
  • 4,219
  • 7
  • 52
  • 80
15
votes
1 answer

Could not install Microsoft.AspNet.Razor 3.0.0

I am working on an ASP.NET project in which I need to do simple HTML templating. The prettiest solution seems to be RazorEngine, which depends on Microsoft.AspNet.Razor. However, when trying to install Microsoft.AspNet.Razor via Nuget, the…
Tahir Hassan
  • 5,715
  • 6
  • 45
  • 65
14
votes
1 answer

RazorEngine templates in VS 2015 - Feature 'implicitly typed local variable' is not available in c# 2

I get the below error when I open RazorEngine cshtml template file in my VS 2015 project. Feature 'implicitly typed local variable' is not available in c# 2. Please use language version 3 or greater. The template compiles correctly, just the…
A.D.
  • 425
  • 3
  • 15
14
votes
4 answers

@Html.ActionLink and Angularjs value?

Hey i'm currently workin on a project that has implemented angularjs, i was wondering if there is a way around to use angular value in Html Helper? This is what I can't get to work: @Html.ActionLink("Edit", "Edit", new { id = {{row.Id}} }) How do…
ShaqCode
  • 381
  • 1
  • 2
  • 10
14
votes
3 answers

RazorEngine un-cache compiled templates

Currently, I am using RazorEngine v2.1 as part of a background process that sends templated emails (thousands of them). To speed things up, the templates are compiled with their md5 sum as a name. This makes it so that when a template is changed, it…
Los Frijoles
  • 4,771
  • 5
  • 30
  • 49
1
2 3
38 39