选择programCategory后,我收到404错误。我想要的是当我点击programCategory时,所有课程都应该显示在该类别下

时间:2015-08-05 17:48:29

标签: asp.net-mvc razor entity-framework-6 code-first

这个问题与我之前的问题有关。

How to search and load data in database by using a string keyword

这是控制器中的索引方法。

    public ActionResult Index(string crsCtgry)
    {
        var viewModel = new DisplayCourseIndexData();

        viewModel.ProgramCategory = db.ProgramCategoriess;
        if (crsCtgry != null)
        {
            viewModel.CourseCategories = db.CourseCategories.Where(n => n.courseField == crsCtgry).Select(n => n).ToList();
        }
        return View(viewModel);
    }

这是Razer-View

<div class="col-sm-4 page-sidebar">
                    <aside>
                        <div class="widget sidebar-widget white-container links-widget">
                            <br>
                            <div class="title-lines">
                                <h4 class="m0" style="color:deepskyblue">Course List</h4>
                            </div>
                            @foreach (var item in Model.ProgramCategory)
                            {
                                <ul class="ullist">
                                    <li>
                                        @Html.ActionLink(item.courseCategory, "Details", new { id = item.courseCategory }, new { @class = "" })
                                    </li>
                                </ul>
                            }
                        </div>
                    </aside>
                </div>




                <div class="col-sm-4 page-content">
                    <div class="white-container mb0">

                        @if (Model.CourseCategories != null)
                        {
                            <h3>Courses Taught by Selected Instructor</h3>
                            <table class="table">
                                <tr>
                                    <th></th>
                                    <th>Number</th>
                                    <th>Title</th>
                                    <th>Department</th>
                                </tr>

                                @foreach (var item in Model.CourseCategories)
                                {
                                    <tr>
                                        <td>
                                            @item.courseSubject
                                        </td>
                                        <td>
                                            @item.courseName
                                        </td>
                                    </tr>
                                }

                            </table>
                        }

                    </div>
                </div>

这是viewModel类

 public class DisplayCourseIndexData
    {
        public IEnumerable<CourseCategory> CourseCategories { get; set; }
        public IEnumerable<ProgramCategories> ProgramCategory { get; set; }
    }

0 个答案:

没有答案