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);
}
精彩评论