简体   繁体   English

使用 Asp.net c# 和 html 混码出现问题

[英]Problem for using Asp.net c# and html mixing code

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.我尝试在 asp.net 中使用以下代码,但 html 标签中存在错误,例如并说它找不到开始标签。 but begin tag is in first if.但是开始标签在第一个如果。 the errors are in between line 44 to 52.错误在第 44 到 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.我也尝试从 if 开头删除 @ 但错误没有删除。

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.我看过你的代码,人们在代码混淆中似乎有一个明显的错误是,在代码中多次输入@符号,虽然你可以在if条件之前看到大括号,但你不应该放一个@符号指定代码,编译器认为它已经是代码而不是标记。 See:看:

大括号问题

Simply, just remove the @ sign from these if conditions and see if error still disturbs you.简单地说,只需从这些if条件中删除 @ 符号,看看错误是否仍然困扰您。

Plus, I must say your html is a little not aligned well, and you got some closing tags missing such as the </thead> tag.另外,我必须说您的 html 对齐不太好,并且缺少一些结束标签,例如</thead>标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM