Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MVC视图,表循环查询_C#_Asp.net Mvc_Loops_View_Html Table - Fatal编程技术网

C# MVC视图,表循环查询

C# MVC视图,表循环查询,c#,asp.net-mvc,loops,view,html-table,C#,Asp.net Mvc,Loops,View,Html Table,这就是我使用静态数据在表内实现此视图所做的 静态代码: <table class="table table-bordered"> <thead class="bordered-darkorange bg-blue"> <tr> <th class="bg-blue">

这就是我使用静态数据在表内实现此视图所做的

静态代码:

   <table class="table table-bordered">
                <thead class="bordered-darkorange bg-blue">

                    <tr>
                        <th class="bg-blue">
                            #
                        </th>
                        <th class="bg-blue">
                            Scheme
                        </th>
                        <th class="bg-blue">
                            Card Type
                        </th>
                        <th class="bg-blue">
                            Commodity
                        </th>
                        <th class="bg-blue">
                            Qty(Kr/Ltr)
                        </th>
                        <th class="bg-blue">
                            Type
                        </th>
                        <th class="bg-blue">
                            Member Count
                        </th>
                    </tr>

                </thead>
                <tbody>

                    @for (int i = 0; i < 4; i++)
                    {
                        <tr>
                            <td>
                                1
                            </td>
                            @if (i == 0)
                            {
                                <td rowspan="4">
                                    Text
                                </td>
                            }
                            @if (i == 0 || i == 2)
                            {
                                <td rowspan="2">
                                    Text
                                </td>
                            }
                            <td>
                                Text
                            </td>
                            <td>
                                <input type="text" class="form-control" style="width: 85%;" maxlength="100" id="txtType" />
                            </td>

                            <td>
                                <select name="ddlDistrict" id="@("CardType"+i)" class="CardType form-control">
                                    <option selected="selected" value="">--Select--</option>
                                    <option value="1">Card Based</option>
                                    <option value="2">Member Based</option>
                                </select>
                            </td>
                            <td>
                                <select name="ddlDistrict" id="@("MemberCount"+i)" class="MemberCount form-control ">
                                    <option selected="selected" value="">--Select--</option>
                                    <option value="1">1</option>
                                    <option value="2">2</option>
                                    <option value="3">3</option>
                                    <option value="4">4</option>
                                    <option value="5">5</option>
                                    <option value="6">6</option>
                                    <option value="7">7</option>
                                    <option value="8">More Than 7</option>
                                </select>
                                <br class="txtMemberCount" id="@("brMemberCount"+i)">
                                <input type="text" class="txtMemberCount form-control" style="width: 85%;" maxlength="100" id="@("txtMemberCount"+i)" />
                            </td>
                        </tr>
                    }

                    @for (int i = 4; i < 8; i++)
                    {
                        <tr>
                            <td>
                                1
                            </td>
                            @if (i == 4)
                            {
                                <td rowspan="4">
                                    Text
                                </td>
                            }
                            @if (i == 4 || i == 6)
                            {
                                <td rowspan="2">
                                    Text
                                </td>
                            }
                            <td>
                                Text
                            </td>
                            <td>
                                <input type="text" class="form-control" style="width: 85%;" maxlength="100" id="txtType" />
                            </td>

                            <td>
                                <select name="ddlDistrict" id="@("CardType"+i)" class="CardType form-control">
                                    <option selected="selected" value="">--Select--</option>
                                    <option value="1">Card Based</option>
                                    <option value="2">Member Based</option>
                                </select>
                            </td>
                            <td>
                                <select name="ddlDistrict" id="@("MemberCount"+i)" class="MemberCount form-control ">
                                    <option selected="selected" value="">--Select--</option>
                                    <option value="1">1</option>
                                    <option value="2">2</option>
                                    <option value="3">3</option>
                                    <option value="4">4</option>
                                    <option value="5">5</option>
                                    <option value="6">6</option>
                                    <option value="7">7</option>
                                    <option value="8">More Than 7</option>
                                </select>
                                <br class="txtMemberCount" id="@("brMemberCount"+i)">
                                <input type="text" class="txtMemberCount form-control" style="width: 85%;" maxlength="100" id="@("txtMemberCount"+i)" />
                            </td>
                        </tr>
                    }

                </tbody>
            </table>
var schemename = (from m in db.SchemeMasters select m).ToList();
        ViewBag.schmname = schemename;

        var cardtypcount = (from t in db.RationCards select t).ToList();
        ViewBag.cardtypcount = cardtypcount;

        var commodity = (from x in db.TagCards select x).ToList();
        ViewBag.commodity = commodity;

根据我从您的解释中了解到的情况,您正在尝试循环通过未知数量的元素,在这种情况下,为什么不尝试foreach。

是的,我也尝试过foreach,但在这种情况下如何进行行跨度?