Ruga Lincy

Ruga Lincy

  • NA
  • 42
  • 6.6k

How to implement paging bar bottom of result page mvc

Aug 26 2015 5:53 AM
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 Frown | :(

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 cm = new List();
using (SYTEntities context = new SYTEntities())
{
cm = context.Database.SqlQuery("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:
 
<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>
<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 "<i style=" padding: 0px 10px; color: #595FFF;">@Session["searched"]</i>"</h2>
</div>
<div>
@foreach (var item in Model)
{
<div class="tiptext">
<b style="margin-left: 0px; font-size: large;color: #1A0DB2;">@item.BusinessName</b>
<h3 style="margin: 5px 0px 5px 0px;color: #009100;"> @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</b>
</div><hr />
<div class="description_body">
<b>Description </b><h4 class="des">@item.BusinessDescription</h4>
<b>Address2 </b><h4 class="des">@item.Address1</h4>
<b>Email </b><h4 style="color:blue; margin: 5px 0px 5px 0px;">@item.EmailID </h4>
<b>WorkNumber </b><h4 class="des">@item.WorkNumber</h4>
<b>MobileNumber </b><h4 class="des">@item.MobileNumber</h4>
<b>City </b><h4 class="des">@item.City</h4>
<b>State </b><h4 class="des">@item.State</h4>
<b>ZipCode </b><h4 class="des">@item.ZipCode</h4>
@Html.ActionLink("Book An Appointment", "CalendarView", "Appt", new { id = @item.UserID }, null)
@*@Html.ActionLink("Book An Appointment", "Popup", "Search", new { @class = "openDialog", data_dialog_id = "aboutlDialog", data_dialog_title = "Additinal Customer" })*@
</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"] }))