Asp.net 为什么我的;柜台;isn';在这个foreach循环中,t是否递增?

Asp.net 为什么我的;柜台;isn';在这个foreach循环中,t是否递增?,asp.net,asp.net-mvc,foreach,Asp.net,Asp.net Mvc,Foreach,对于每张卡片,我试图分配一个“modalId”,以便在每个课程卡片的模式弹出时,它可以显示“@item.description”。但是,我无法获取“@int-modal”,它随后会转换为“modalstring”,以使“modalId”递增。真奇怪。这是asp.net mvc btw中的cshtml文件 <div id="courses-list" class="container"> <h1 id="heading" class="heading">Availa

对于每张卡片,我试图分配一个“modalId”,以便在每个课程卡片的模式弹出时,它可以显示“@item.description”。但是,我无法获取“@int-modal”,它随后会转换为“modalstring”,以使“modalId”递增。真奇怪。这是asp.net mvc btw中的cshtml文件

<div id="courses-list" class="container">
    <h1 id="heading" class="heading">Available Courses</h1>
    <p style="text-align:center">Click images to view course details!</p>
    <div class="row">
        @{ int i = 0;}
        @{if (Model.Courses.Count == 0)
            {
                <p>You are not enrolled in any courses.</p>
            }
            else
            {
                int b = 20;
                var distinctList = Model.Courses.Distinct().ToList();
                if (distinctList[0].Image != null)
                {
                    @{int modal = 0;}
                    foreach (var item in distinctList)
                    {
*this line*             modal = modal++;
                        string modalString = modal.ToString();

                        <div class="four columns">
                            <div class="new-card">



                        <img src="@Url.Content(item.Image.FilePath)" class="course-image u-full-width" style="cursor:pointer" data-toggle="modal" data-target="#@modalString">
                            <div class="info-card">
                                <h4 class="course-name">@item.CourseName.ToUpper()</h4>
                                @{ string teacher = "";}
                                @foreach (var user in Model.Users)
                                {

                                    if (item.TeacherId == user.UserId)
                                    {
                                        teacher = user.FirstName + user.LastName;
                                    }

                                }
                                <p class="course-author">by @teacher</p>
                                <p>
                                    @if (item.CourseRating > 0 && item.CourseRating < 1.5)
                                    {
                                        @*<h4>@item.CourseRating Stars</h4>*@
                                        <span class="fa fa-star checked"></span>
                                        <span class="fa fa-star"></span>
                                        <span class="fa fa-star"></span>
                                        <span class="fa fa-star"></span>
                                        <span class="fa fa-star"></span>
                                    }
                                    @if (item.CourseRating > 1.5 && item.CourseRating < 2.5)
                                    {
                                        @*<h4>@item.CourseRating Stars</h4>*@
                                        <span class="fa fa-star checked"></span>
                                        <span class="fa fa-star checked"></span>
                                        <span class="fa fa-star"></span>
                                        <span class="fa fa-star"></span>
                                        <span class="fa fa-star"></span>
                                    }
                                    @if (item.CourseRating > 2.5 && item.CourseRating < 3.5)
                                    {
                                        @*<h4>@item.CourseRating Stars</h4>*@
                                        <span class="fa fa-star checked"></span>
                                        <span class="fa fa-star checked"></span>
                                        <span class="fa fa-star checked"></span>
                                        <span class="fa fa-star"></span>
                                        <span class="fa fa-star"></span>
                                    }
                                    @if (item.CourseRating > 3.5 && item.CourseRating < 4.5)
                                    {
                                        @*<h4>@item.CourseRating Stars</h4>*@
                                        <span class="fa fa-star checked"></span>
                                        <span class="fa fa-star checked"></span>
                                        <span class="fa fa-star checked"></span>
                                        <span class="fa fa-star checked"></span>
                                        <span class="fa fa-star"></span>
                                    }
                                    @if (item.CourseRating > 4.5 && item.CourseRating <= 5)
                                    {
                                        @*<h4>@item.CourseRating Stars</h4>*@
                                        <span class="fa fa-star checked"></span>
                                        <span class="fa fa-star checked"></span>
                                        <span class="fa fa-star checked"></span>
                                        <span class="fa fa-star checked"></span>
                                        <span class="fa fa-star checked"></span>
                                    }
                                </p>
                                <p class="price">
                                    @if (item.Difficulty == 1)
                                    {
                                        <span style="color:greenyellow">Beginner</span>
                                    }
                                    else if (item.Difficulty == 2)
                                    {
                                        <span style="color:green">Easy</span>
                                    }
                                    else if (item.Difficulty == 3)
                                    {
                                        <span style="color:orange">Intermediate</span>
                                    }
                                    else if (item.Difficulty == 4)
                                    {
                                        <span style="color:orangered">Difficult</span>
                                    }
                                    else
                                    {
                                        <span style="color:red">Expert</span>
                                    }  <span class="u-pull-right" style="text-decoration:line-through">$15</span>
                                </p>
                                @Html.ActionLink("Enroll Now", "addCourseToStudent", "Home", new { courseId = item.CourseId }, new { @class = "u-full-width button-primary button input add-to-cart" })
                            </div>
                            <!--.card-->
                            <div id="@modalString" class="modal fade" role="dialog">
                                <div class="modal-dialog">

                                    <!-- Modal content-->
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <h4 class="modal-title">@item.CourseName</h4>
                                        </div>
                                        <p class="modal-teacher">by @teacher</p>
                                        <div class="modal-body">
                                            <p>@item.Description</p>
                                        </div>
                                        <div class="modal-footer">
                                            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                        </div>
                                    </div>

                                </div>
                            </div>

                        </div>

                    </div>
                }
            }
        }
    }


  </div>
 </div>

现有课程

单击图像查看课程详细信息

@{int i=0;} @{如果(Model.Courses.Count==0) { 你没有参加任何课程

} 其他的 { int b=20; var distinctList=Model.Courses.Distinct().ToList(); if(distinctList[0]。Image!=null) { @{int modal=0;} foreach(distinctList中的变量项) { *此行*modal=modal++; 字符串modalString=modal.ToString(); @item.CourseName.ToUpper() @{string teacher=”“;} @foreach(Model.Users中的var用户) { if(item.TeacherId==user.UserId) { 教师=user.FirstName+user.LastName; } }

作者@teacher

@如果(item.coursering>0和&item.coursering<1.5) { @*@项目1.1:恒星*@ } @如果(item.Coursing>1.5和item.Coursing<2.5) { @*@项目1.1:恒星*@ } @如果(item.Coursing>2.5和item.Coursing<3.5) { @*@项目1.1:恒星*@ } @如果(item.Coursing>3.5和item.Coursing<4.5) { @*@项目1.1:恒星*@ } @如果(item.Coursing>4.5&&item.Coursing @项目.CourseName

作者@teacher

@项目.说明

接近 } } } }
modal=modal++;
=>它应该是
modal++
吗?检查这些帖子:&。是的,我想我真的很累了。我还没有检查,但你是对的。祝你好运(:由于某种原因,modalstring仍然没有显示,尽管它们有其指定的/唯一的id…ffsyeah在开发工具中代码看起来很好,但是关于modals一定有一些我不知道的地方。是的。我将modalstring更改为“modal”+modal.toString(),出于某种原因,它们现在都在工作。太愚蠢了。案例结束。