LINQ :.选择无限循环

时间:2015-07-22 15:06:51

标签: linq asp.net-mvc-5

我在LINQ或某种JQuery中得到似乎是无限循环的东西。 一直在反复调用Controller方法。 这是我的控制器方法:

    public ActionResult Index()
    {
        // TODO: decide what properties determine a need for User Action (the 'where(s)')
        var viewModel = new PriorityTasksViewModel
        {
            BayOptions = _bayOptionRepository.GetBayOptions()
                .Where(x => x.IsActive && !x.SiteVisibilityFlagsOverride).ToList()
                .Select(x => new PriorityTasksBayOptionsViewModel() 
                {
                    BayGuid = x.BayGUID, 
                    BayNumber = x.BayNumber, 
                    PropertyId = x.PropertyId
                })
                .ToList(),
            Properties = _propertyRepository.GetProperties()
                .Where(x => !x.SiteVisibilityFlagsOverride).ToList()
                .Select(x => new PriorityTasksPropertiesViewModel() 
                {
                    PropertyId = x.PropertyId, 
                    PropertyName = x.Name
                })
                .ToList()
        };
        return View("_PriorityTasks", viewModel);
    }

如果我在视图中放置一个断点,我会验证它的循环。我的LINQ中缺少什么?我把.ToList()放在那里强制加载,但...... 视图:

<h6>Properties</h6>

<table class="table">
<tr>
    <th>
        Name
    </th>       
</tr>
@foreach (var item in Model.Properties) {
<tr>
    <td>
        <a href="@(Url.Action("Edit", "Property"))">@Html.DisplayFor(modelItem => item.PropertyName)</a>
    </td>
</tr>
}
</table>

_Layout底部的JQuery :(它必须在布局菜单上显示)

 $(document).ready(function () {
    $('#PriorityTasks').load('@Url.Action("Index", "PriorityTask")');
})

2 个答案:

答案 0 :(得分:1)

也许您需要返回部分视图

#include <cstring>         // C++ header file for C-style string routines
... 
char buf[N];               // N is large enough for your input plus 0 terminator
while ( std::cin.get( buf, sizeof buf ) && std::strcmp( buf, " " ) != 0 )
  myWords.push_back ( std::string( buf ) );

答案 1 :(得分:0)

我认为如果你想保留一个布局,你可以使用局部视图。

控制器:

public ActionResult Images(int? page)
{
    int pageNumber = page ?? 1;
    page = page ?? 1;
    var images = db.image.AsQueryable().OrderBy(x => x.name);

    var onePageOfImages = images.ToPagedList(pageNumber, pageSize);
    ViewBag.onePageOfImages = onePageOfImages;

    return (page == 0)
        ? PartialView()
        : (ActionResult)PartialView("_ImageList");
}

Images.cshtml

@{
    ViewBag.Title = "Image List";
}
@using PagedList;
@using PagedList.Mvc;

@Styles.Render("~/Content/PagedList.css")

<h2>Image List</h2>

@DateTime.Now.ToString()

<div id="unobtrusive">
    @Html.Partial("_ImageList")
</div>

和_ImageList

 @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.name)