IEnumerable View.this보기 페이지 (cshtml)는 모델 데이터와 form.it의 일부 데이터를 통합하여 데이터베이스에서 내 모델의 모든 데이터를 나열합니다.
asp.net에서 결과 집합 필터링 mvc3
[HttpPost]
public ViewResult SearchPost()
{
var posts =db.posts.Include("user").ToList();
if (Request.Form["searchString"] != null)
{
posts = (from posts in db.posts where posts.area
==Request .Form["searchString"]).ToList();
}
if (Request.Form["searchString2"] != null)
{
posts = (from posts in db.posts where posts.city
==Request.Form["searchString2"]).ToList();
}
if (Request.Form["searchString3"] != null)
{
posts = (from posts in db.posts where posts.floor
==Request.Form["searchString3"]).ToList();
}
return View(posts);
}
내보기 페이지 :
나는 그런 도시, 지역, 바닥, 도로없는 등 모든 필터는이 같은 내 양식의 field.My 작용에 의해 필터로 다수의 필터 옵션으로 그 데이터를 필터링 할 @using (Html.BeginForm()){
<p> Area: @Html.TextBox("SearchString")
<p> City: @Html.TextBox("SearchString2")
<p> Floor: @Html.TextBox("SearchString3")
<input type="submit" value="Filter" /></p>
}
>.....list of Model Data
내 모든 필터 옵션은 선택 사항입니다. 하나 또는 다수의 필터 옵션이 선택 될 수 있거나 선택되지 않을 수있다. 그것은 오류를 준다 범위 변수 게시물 각 if 조건 블록 내 결과 집합을 필터링 할. 그것은 가능합니까 ??? 가능하다면 아이디어를주세요.
오류 메시지와 관련하여 구체적으로 말씀해 주시겠습니까? – MikeTWebb