Closed mirrortom closed 1 year ago
Why are HTML tags parsed into C# code?
because razor is compiled template engine, thats why its really fast
this code works for me, I dont see any issues:
class Program
{
static string Content = @"<input name=""firstname"" type=""text"" value=""""/><div>@Model.Name</div>";
static void Main(string[] args)
{
IRazorEngine razorEngine = new RazorEngine();
IRazorEngineCompiledTemplate template = razorEngine.Compile(Content);
string result = template.Run(new
{
Name = "Alexander"
});
Console.WriteLine(result);
Console.ReadKey();
}
}
Thanks for you reply! Author, Alexander.
I tried to write 4 commas :
<input name="firstname" type="text" value=""""/>
but same situation(source is a (.cshtml) file)
...
BeginWriteAttribute("value", " value=\"", 252, "\"", 468, 5);
...
I tested other project similar to yours, the RazorEngine and RazorLight,and didn't find this situation
I think the class RazorProjectEngine created, Some features for razor parsing are missing. I tried some features add to RazorProjectEngineBuilder,but all faild, I didn't find that one that worked.
(RazorProjectEngineBuilder builder)
{
}
If prop value is not empty, then the compilation is correct
// source
<input name="firstname" type="text" value="AAA" />
// Generated
WriteLiteral("\r\n <input name=\"firstname\" type=\"text\" value=\"AAA\" /> \r\n");
may I ask you to provide sample console app code to reproduce this problem?
em...,I am sorry. I recloned RazorEngineCore and tested the issue in the new console program, It was no problem! I should double-check my project. Thank you very much!
at last I found the problem, the TemplateBase.cs file was missing the BeginWriteAttribute() and EndWriteAttribute() methods
`
`
when the prop
then razor parse doc is
Why are HTML tags parsed into C# code?