question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

when empty value prop on html tag,razor doc parse error

See original GitHub issue

<input name="firstname" type="text" value=""/>

when the prop

value=“”

then razor parse doc is

#nullable disable
WriteLiteral(“"”);
BeginWriteAttribute(“value”, " value="“, 252, “”, 468, 5); WriteAttributeValue(”", 260, “></div>”, 260, 7, true); …

Why are HTML tags parsed into C# code?

Issue Analytics

  • State:closed
  • Created 4 months ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mirrortomcommented, May 29, 2023

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

1reaction
adoconnectioncommented, May 28, 2023

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();
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How does a HTML parser know when empty element ends
Answer : Yes, HTML parsers have finite list of empty elements. The parser have certain rules for parsing and will ignore the empty...
Read more >
[vite:build-html] Unable to parse html in build step #4067
Describe the bug using vite with vite-plugin-string for importing html as strings dev mode works great, but when trying to build for ...
Read more >
Ignore attribute when attribute content is invalid #141
This sounds like invalid CSS in your HTML. See 'The parser throws an error'.
Read more >
Uncaught TypeError: Cannot read property of null - iDiallo
We want to get the value of an input. var inputVal = document. ... i get the error code cannot read property "options"...
Read more >
Razor syntax reference for ASP.NET Core
Razor evaluates C# expressions and renders them in the HTML output. When an @ symbol is followed by a Razor reserved keyword, it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found