hi all. am trying to implement paging bar( < 1 2 3 >) bottom of result page.. my code
am getting
Object reference not set to an instance of an object.
someone help me to solve this :(
Controller
[HttpPost]
public ActionResult Index(string txtValue, string txtLocation, string Filter_Value, int? Page_No)
{
var s = txtValue.ToString();
Session["searched"] = s;
var l = txtLocation.ToString();
Session["location"] = l;
ViewBag.plist = txtValue;
if (txtValue != null)
{
Page_No = 1;
}
else
{
txtValue = Filter_Value;
}
ViewBag.FilterValue = txtValue;
if (txtValue.Length > 0)
{
string[] keywords = txtValue.Trim().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
string[] keyword = txtLocation.Trim().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
var parameter = new SqlParameter[2];
parameter[0] = new SqlParameter { ParameterName = "@SEARCH", Value = txtValue };
parameter[1] = new SqlParameter { ParameterName = "@loc", Value = txtLocation };
List<search> cm = new List<search>();
using (SYTEntities context = new SYTEntities())
{
cm = context.Database.SqlQuery<search>("exec search_filter_sp @SEARCH,@loc", parameter).ToList();
}
//int Size_Of_Page = 3;
//int No_Of_Page = (Page_No ?? 1);
return View(cm.ToList().ToPagedList(Page_No?? 1, 3));
}
else
{
ViewBag.Message = true;
return View();
}
}
View:
PagedList.IPagedList<SYTMain.Models.Search>
@using PagedList.Mvc;
<link href="~/Content/PagedList.css" rel="stylesheet" />
<div class="searchform cf">
@using (Html.BeginForm())
{
<input type="search" name="txtValue" id="txtValue" value="@Session["searched"]" placeholder="Need Service ? " spellcheck="true">
<input type="search" name="txtLocation" id="txtLocation" value="@Session["location"]" placeholder=" City or State">
<button type="submit" value="Search" style="margin-top: 5px;">Search</button>
}
<div style="margin: 35px 0px 0px 90px">
@if (ViewBag.Message == true)
{
<label id="lblMessage" title="Please enter keyword" style="color:red;">Please enter keyword...!</label>
}
else
{
if (Model != null)
{
if (Model.Count() != 0)
{
<div>
<h2 style="font-size: 15px;">Searched for "0 10px; color: rgba(89, 95, 255, 1)">@Session["searched"]"</h2>
</div>
<div>
@foreach (var item in Model)
{
<div class="tiptext">
"font-size: large; color: rgba(26, 13, 178, 1)"__^ @item.FirstName</h3>
<h3 style="margin: 8px; color:black">@item.BusinessCategory </h3>
<div class="description">
<div class="description_image">
<img src="~/Images/popup_pointer.jpg" />
<div class="POP_UP_outer">
<div class="description_background">
<div class="description_map">
^__b>Map
</div><hr />
<div class="description_body">
^__b>Description <h4 class="des">@item.BusinessDescription</h4>
^__b>Address2 <h4 class="des">@item.Address1</h4>
/div>
</div>
</div>
</div>
</div>
</div>
}
</div>
}
else
{
<label id="lblErrorMsg" title="Record not fount...!" style="color:red;">Record not found...!</label>
}
}
}
</div>
</div>
<br />
@Html.PagedListPager(Model, page => Url.Action("Index", new { page, txtValue = Request.QueryString["txtValue"], txtLocation = Request.QueryString["txtLocation"] }))