Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC Razor <text> tag not accepting less than or equal to operators

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&lt/p>"). If you intended to display a "<" character, use the "<" HTML entity.

enter image description here

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.

like image 955
SharK Avatar asked Nov 12 '18 22:11

SharK


2 Answers

As a workaround, you can use @Html.Raw("<=") instead of <=.

like image 103
Shimon Lebovits Avatar answered Oct 05 '22 23:10

Shimon Lebovits


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 
like image 42
Mshdi Ojaghi Avatar answered Oct 06 '22 00:10

Mshdi Ojaghi