如何使用int循环进行搜索 [英] How To search using int loop
本文介绍了如何使用int循环进行搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试从1到30列出int值,但直到现在它不起作用的是我的控制器
I try to listing int value from 1 till 30 but until now its not work here is my controller
var lis = new List<int>();
lis.AddRange(Enumerable.Range(1, 30));
ViewBag.listku = Enumerable.Range(1, 30).ToString();
var lispeserta = from item in db.Klaim
select item;
if(!string.IsNullOrEmpty(listku))
{
lispeserta = lispeserta.Where(x => x.NoPeserta == listku);
}
return View(lispeserta);
这是我的观点
and here is my view
@using (Html.BeginForm("Index", "Klaim", FormMethod.Get))
{
<title>search</title>
@Html.DropDownList("listku","Semua") <input type="submit" value="Filter" />
}
错误消息显示具有密钥'listku'的ViewData项的类型为'System.String '但必须是'IEnumerable< SelectListItem>'类型。
我该怎么办?
the error message says "The ViewData item that has the key 'listku' is of type 'System.String' but must be of type 'IEnumerable<SelectListItem>'."
how should I do?
推荐答案
嗯,你可以尝试比较相同的数据类型!
假设ViewBag.listku
和listku
是一回事,它包含的值将是类的名称 - 它将沿着System.Linq.Enumerable +< rangeiterator> d__1的行而不是您期望的数字。
可能你想做这样的事情:
Well, you could try comparing the same datatypes!
Assuming thatViewBag.listku
andlistku
are the same thing, the value it contains will be the name of the class - which is going to be along the lines of "System.Linq.Enumerable+<rangeiterator>d__1" rather than the numbers you expect.
Probably you want to do something like this:
var listku = Enumerable.Range(1, 30);
var lispeserta = from item in db.Klaim
select item;
lispeserta = lispeserta.Where(x => listku.Contains(x.NoPeserta));
return View(lispeserta);
尔加!再次降价![/ edit]
[edit]Gah! Markdown again![/edit]
这篇关于如何使用int循环进行搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文