开发者

Using the Take Method on my model Substitute Variable

开发者 https://www.devze.com 2023-04-11 12:46 出处:网络
Basically I want to have a way to select the number in my foreach(var sheet in Model.Sheets.Take(100))

Basically I want to have a way to select the number in my

foreach(var sheet in Model.Sheets.Take(100))
{
...
}

I would like the user to be able to specify this value and开发者_Python百科 reload the page using the take method, how can this be done?


Why not pass a parameter in to your controller?

public ActionResult Index(int? toTake)
{
    foreach(var sheet in Model.Sheets.Take(toTake != null ? toTake.Value : 100))
    {
    }

    return View();
}


If this is in your View, you're doing it wrong.

Do this .Take() bit in your controller actions and pass along an IEnumerable<T> to your view.

For example:

public ActionResult Index(int? pageSize)
{
    MyViewModel model = new MyViewModel();

    foreach(var sheet in Model.Sheets.Take(pageSize != null ? pageSize : 20))
    {
        //yada yada yada. Do something here with sheet and model.
    }

    return View(model);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消