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);
555 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,773
  • 2
  • 19
  • 32
34
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,393
  • 3
  • 25
  • 43
32
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
  • 965
  • 4
  • 16
  • 31
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…
21
votes
2 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,350
  • 2
  • 14
  • 26
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
  • 552
  • 6
  • 15
20
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
  • 8,708
  • 20
  • 80
  • 127
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
  • 43,414
  • 51
  • 157
  • 277
16
votes
4 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
  • 878
  • 8
  • 25
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,024
  • 6
  • 45
  • 74
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,299
  • 5
  • 40
  • 61
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,501
  • 3
  • 27
  • 46
12
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.
  • 295
  • 2
  • 12
10
votes
1 answer

RazorEngine.Text.RawString not working on regular MVC partial view

I reuse the same partial for a RazorEngine email using RazorEngine.Parse, but when I use the same Partial in a regular view new RazorEngine.Text.RawString doesnt work and doesnt ignore HTML. I cant use Html.Raw because the RazorEngine cant read it.…
Mike Flynn
  • 21,905
  • 50
  • 167
  • 308
1
2 3
36 37