0
votes

Using VS2019 Version 16.6.5 Razor Page Model. Core 3.1

@{
    if (Model.Mode != enAccessMode.Read)
    {
        <text>
        $("#mTable tbody tr div").removeClass("TrError").
            find("[data-title]").removeAttr("data-title");
        var errs = JSAns.CollectData();
        if (errs !== null) {
            for (var i = 0; i < errs.length; i++) { // Razor doesn't likes the < here!!!!!
                var err = errs[i];
                var e = $("#mQ_" + err.ErrQID);
                e.addClass("TrError");
                e.attr("data-title", err.ErrMsg);
            }
            $("#mQ_" + errs[0].ErrQID)[0].scrollIntoView();
            return;
        }
        </text>
    }
}

The compiler doen't like the < symbol at line 9. It gives the error below during compilation. using the &lt; doesn't help at all, since it is a javascript code, not a text string.

End of file or an unexpected character was reached before the "" tag could be parsed. Elements inside markup blocks must be complete. They must either be self-closing ("<br />") or have matching end tags ("<p>Hello</p>"). If you intended to display a "<" character, use the "&lt;" HTML entity.

1

1 Answers

2
votes

As the error shows, the razor will regard the < as the uncomplete html tag. To solve this issue, I suggest you could try below work around.

@Html.Raw("<")

Whole codes:

    <text>
        $("#mTable tbody tr div").removeClass("TrError").
        find("[data-title]").removeAttr("data-title");
        var errs = JSAns.CollectData();
        if (errs !== null) {
        for (var i = 0; i @Html.Raw("<") errs.length; i++) {
        var err = errs[i];
        var e = $("#mQ_" + err.ErrQID);
        e.addClass("TrError");
        e.attr("data-title", err.ErrMsg);
        }
        $("#mQ_" + errs[0].ErrQID)[0].scrollIntoView();
        return;
        }

    </text>