0

I tried to use below code in asp.net but there is error in html tags like and and say it could not find begin tag. but begin tag is in first if. the errors are in between line 44 to 52.

@{
    string n = "";
    int j = 0;
    foreach (var item in Model.RelatedProduct)
    {
        if (item.ProductId != n)
            j = 1;
        else
            j = 0;            
        if(j==1)
        {
            <div class="modal fade" id="myModal" role="dialog">
                <div class="modal-dialog modal-dialog-centered " role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title">@item.CatalogDescription</h5>
                            <button class="close" type="button" data-dismiss="modal">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                        <div class="modal-body">
                            <table class="table table-hover">
                                <thead class="thead-dark">
                                    <tr>
                                        <td>Customer</td>
                                    </tr>
        }
        @if(j == 1 || j == 0)
        {
                                    <tr>
                                        <td>@item.CustomerName</td>
                                        <td>@item.Price</td>
                                    </tr>
        }
        @if(j==1) 
        { 
                            </table>
                        </div>
                        <div class="modal-footer">
                             <button class="btn" data-dismiss="modal">Cancel</button>
                        </div>
                     </div>
                  </div>
                </div>
        }
    }
}

and also i tried to remove @ from beginning of if but the error don't remove.

2
  • You are missing </thead> closing tag. If adding that tag doesn't solve the problem, could you tell us what are the lines 44 to 52? Commented May 2, 2020 at 23:33
  • not only the </thead> closing tag, you are also messing around with if else razor syntax, you need to clear your conditions and usage of html tags within if else in razor. you are actually mixing the code. Commented May 2, 2020 at 23:50

1 Answer 1

1

I have seen your code and it seems an obvious mistake in the Code mix-up that people do is, put @ sign multiple times in the code, while you can see the curly brace before the if condition, you were not supposed to put an @ sign to specify the code, compiler thinks it is already code instead of markup. See:

Brace Issue

Simply, just remove the @ sign from these if conditions and see if error still disturbs you.

Plus, I must say your html is a little not aligned well, and you got some closing tags missing such as the </thead> tag.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.