I have a JavaScript if condition containing some comparison operators (<=, >=) inside a partial view. This JavaScript is surrounded by MVC the Razor <text> tags.
With this, my JS is dynamically loading based on the Model properties. However if I have comparison operators in the JavaScript method, it is throwing an error.
Working scenario:
    @if (Model.SomeTrueCondition)
    {
        <text>
        function JSMethod() {
            AnotherJSMethod();
            return;
        }
        </text>
    }  
Not working scenario (if I call the AnotherJSMethod() using comparison operators)
    @if (Model.SomeTrueCondition)
    {
        <text>
        function JSMethod() {
            // This if condition containing comparison operators are not being accepted!
            if ($('#aTextBox').val().length <= 0 || $('#bTextBox').val().length <= 0) {
                AnotherJSMethod();
                return;
            }
        }
        </text>
    }
I tried moving this JS method in another .js file and tried embedding the below way but I still see the same issues.
@section JavaScriptIncludes
{
   <script type="text/javascript" src="@Url.Content("/Scripts/SomeScript.js")" />
}
Getting below error,
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: 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 "<" HTML entity.

Pl. can someone tell me what am I missing here!
Feel free to correct the question/content/tags in order to reach out to right people.
As a workaround, you can use @Html.Raw("<=") instead of <=.
I just add this comment //> after loop block and worked for me :)
like this:
for(let i =0;i<=10;i++){//>//in some where it was working
//your code here
}//>//in some where it was working 
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With