如何在TABLE中使用if else条件 [英] How to use if else condition in TABLE

查看:139
本文介绍了如何在TABLE中使用if else条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨大家好!

我面临问题我想添加Tr如果条件为真且条件为假它将在现有tr中添加td但是它会给出错误td而不是嵌套在表格中。

hi Guys!
I am facing problem i want to add Tr if the condition is true and if the condition is false it will add td in existing tr but it will give an error td not nested in table.

foreach (var r in Model)
        {

            var stationName = "";

            if (r.stationName != stationName)
            {
                <tr class="row-2 even">

                    <td class="Cell2">@r.stationName</td>

                    <td class="Cell2 kara">@if (r.cityId == 1)
                    {@r.contactNo}</td>

                    <td class="Cell2 lhr">@if (r.cityId == 2)
                    {@r.contactNo}</td>

                    <td class="Cell2 isl">@if (r.cityId == 3)
                    {@r.contactNo}</td>

                    <td class="Cell2 psh">@if (r.cityId == 4)
                    {@r.contactNo}</td>

                    <td class="Cell2 qut">@if (r.cityId == 5)
                    {@r.contactNo}</td>

                    <td class="Cell2 fas">@if (r.cityId == 6)
                    {@r.contactNo}</td>

                      </tr>
                    }
                    else
                    {
                    <td></td>

                    }
              
                stationName = r.stationName;
            }
        }





我的尝试:



我如何解决这个问题请指导。



What I have tried:

How can i solve this problem any guide please.

推荐答案

你在foreach关键字之前缺少@符号,这应该是给你语法错误。



You are missing the @ symbol before foreach keyword, which should give you syntax error.

@foreach (var r in Model)





希望,它有帮助:)



Hope, it helps :)


如果有条件,你的tr必须放在外面。



Your tr must be placed outside if condition.

foreach (var r in Model)
        {
 
            var stationName = "";
 <tr class="row-2 even">
 
                  
            if (r.stationName != stationName)
            {
                <td class="Cell2">@r.stationName</td>
}
else
{
<td></td>
}
</tr>
 


我的代码中没有符号我的问题是,在else语句中的最后一个TD标签不起作用它给了我一个错误td没有嵌套在表格中。
No i have symbol in my code my question is that at the last in else statement TD tag is not working it gives me an error td is not nested in table.


这篇关于如何在TABLE中使用if else条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆