Asp.net mvc 2 搜索字符串相同如何不工作
我正在尝试执行一个简单的搜索,我无法找到我在这里错过了什么 这是我的(我认为非常简单的代码) 我的看法Asp.net mvc 2 搜索字符串相同如何不工作,asp.net-mvc-2,Asp.net Mvc 2,我正在尝试执行一个简单的搜索,我无法找到我在这里错过了什么 这是我的(我认为非常简单的代码) 我的看法 <div class="search"> <% using (Html.BeginForm()) { %> <p> Find: <%=Html.TextBox("SearchString", ViewData["currentFilter"] as string) %>
<div class="search">
<% using (Html.BeginForm())
{ %>
<p>
Find: <%=Html.TextBox("SearchString", ViewData["currentFilter"] as string) %>
<input type="submit" value="Search" />
</p>
<%} %>
</div>
//in a brackpoint I can c that the typed parameter is pass to
// if(!string.IsNullOrEmpty(searchString))
查找:
//在括号点中,我可以将类型化参数传递给c
//如果(!string.IsNullOrEmpty(searchString))
我知道在我看来我错过了同样的事情,我只是想知道是什么
谢谢您的代码中有几行我看不懂 为什么在搜索后使用
\u repository
,是否应使用weeklyS
变量
试试这个
ViewData["weeklyS"] = weeklyS.ToList();
int hlist = weeklyS.Count();
ViewData["TotalPages"] = (int)Math.Ceiling((double)hlist / PageSize);
ViewData["CurrentPage"] = page;
return View(weeklyS.Skip((page - 1) * PageSize).Take(PageSize));
看起来您没有将
weeklyS
变量分配到ViewData[“weeklyS”]
试试这个
ViewData["weeklyS"] = weeklyS;
而不是这个
ViewData["weeklyS"] = _repository.List().ToList();
为什么不调试一下,看看会发生什么呢?我调试过了,页面刚刚刷新-我想问题出在我的视图中(搜索:我在使用ViewData[“weeklyS”]时遇到了这个错误)=weeklyS;>>>>对象引用未设置为对象的实例。异常详细信息:System.NullReferenceException:对象引用未设置为对象的实例。源错误:第45行:if(!string.IsNullOrEmpty(searchString))第46行:{第47行:weeklyS=weeklyS。其中(v=>v.UHeadLine.ToUpper().Contains(searchString.ToUpper())同一错误消息:未将对象引用设置为对象的实例。说明:在执行当前web请求期间发生未处理的异常。请查看堆栈跟踪以了解有关错误及其源代码的详细信息。异常详细信息:System.NullReferenceException:未设置对象引用源错误:第45行:如果(!string.IsNullOrEmpty(searchString))第46行:{47行:weeklyS=weeklyS.Where(v=>v.UHeadLine.ToUpper()。包含(searchString.ToUpper())堆栈跟踪显示
weeklys
的值来自var-weeklys=from c in _repository.List().OrderBy(x=>x.UParasha)选择c;
为null尝试var-weeklys=(from c in _repository.List()选择c.OrderBy(x=>x.UParasha);
使用{var-weeklys=(from c in _repository.List()选择c.)OrderBy(x=>x.UParasha);)我进入了(weeklyS=weeklyS.Where(x=>x.UHeadLine.ToUpper()。包含(searchString.ToUpper())一个错误,它说:“显式转换存在(是否缺少转换?)”我尝试在没有if{}的情况下运行它,并在其到达时放置一个断点。我在结果中仍然为空。请尝试使用其类型而不是匿名类型重新声明weeklys
。tryList weeklys
其中myType
是查询返回的项目类型。
ViewData["weeklyS"] = _repository.List().ToList();