网格MVC分页无法正常工作

时间:2015-01-26 08:09:43

标签: c# asp.net-mvc-4 mvcgrid

https://gridmvc.codeplex.com/

这是我想要实现的功能,应该有一个文本框,它带有参考编号,在提交时,网格应该显示该特定参考编号的记录。默认情况下,第一次加载网格时,应该没有记录。按下Show All按钮时,网格显示数据库中的所有记录。

我已经实现了所有但问题是当我搜索特定的参考号时,它会显示该特定号码的记录,但是分页不能正常工作。它显示了正确的页数,但是当我点击时可以说页码" 2"它获取第2页上的所有记录,而不是该特定参考号。

查看

@using GridMvc.Html
@using GridMvc.Sorting
@model IEnumerable<GridMvc.Models.Logging>



<div  style="padding-top:50px;padding-left:15px;padding-right:15px">

@using (Html.BeginForm("Index", "Home"))
{
    <label>Enter Customer Reference Number</label>

    <div>
        <input type="text" value="" style="width:100px" name="subno"/>            
        <div style="margin-top:5px"></div>
        <table>
            <tr>
                <td><input type="submit" value="Search" name="Submit" /> </td>
                <td style="padding-left:5px"><input type="submit" value="Show All" name="Clear" /></td>
            </tr>
        </table>            
    </div>
        <div style="margin-top:15px"></div>

    @Html.Grid(Model).Columns(columns =>
        {
            /* Adding "OrderID" column: */

            columns.Add(o => o.ID)
                   .Titled("Number")
                   .SetWidth(100)
                    .Css("csstd");  
            columns.Add(o => o.Date, "Date")
                    .Titled("Date")
                    .SortInitialDirection(GridSortDirection.Descending)
                    .Format("{0:dd/MM/yyyy}")
                    .SetWidth(110)
                    .Css("csstd");                
            columns.Add(o => o.Time, "Time")
                    .Titled("Time")                
                    .SetWidth(110)
                    .Css("csstd");           
            columns.Add(o => o.Type)
                   .Titled("Type")
                   .SetWidth(150)
                   .Css("csstd")   
                   .ThenSortByDescending(o => o.ID);               
            columns.Add(o => o.Description)
                    .Css("csstd")         
                   .Titled("Description")
                   .SetWidth(250);
            columns.Add(o => o.Reference)
                    .Css("csstd")
                    .Titled("MSISDN")
                    .SetWidth(150);
            columns.Add(o => o.Response)
                    .Css("csstd")
                    .Titled("Response")
                    .SetWidth(150);                




        }).WithPaging(15).Sortable().Filterable().WithMultipleFilters()

}

</div>

控制器

  public ActionResult firstRun()
{
    return View("Index", new List<GridMvc.Models.Logging>());
}

public ActionResult Index(FormCollection form)
{
    wmas_subsEntities entitymodel = new wmas_subsEntities();

    string subno = form["subno"];

    List<GridMvc.Models.Logging> Logs = new List<Models.Logging>();

    if (form["Clear"] != null)
    {
        foreach (var item in entitymodel.Loggings.ToList())
        {
            DateTime ConvertedTime = GetConvertedTime(DateTime.Parse(item.DateTime.ToString()));

            Logs.Add(new Models.Logging()
            {
                Date = ConvertedTime,
                Description = item.Description,
                ID = item.ID,
                Reference = item.Reference,
                Response = item.Response,
                Time = String.Format("{0:h:mm tt}", ConvertedTime),
                Type = item.Type
            });
        }
    }
    else if (subno != null)
    {
        var items = from p in entitymodel.Loggings where p.Reference.Contains(subno) select p;
        if (items.Count() > 0)
        {
            foreach (var Childitem in items)
            {
                DateTime ConvertedTime = GetConvertedTime(DateTime.Parse(Childitem.DateTime.ToString()));

                Logs.Add(new Models.Logging()
                {
                    Date = ConvertedTime,
                    Description = Childitem.Description,
                    ID = Childitem.ID,
                    Reference = Childitem.Reference,
                    Response = Childitem.Response,
                    Time = String.Format("{0:h:mm tt}", ConvertedTime),
                    Type = Childitem.Type
                });
            }
        }
    }
    else
    {
        foreach (var Childitem in entitymodel.Loggings)
        {
            DateTime ConvertedTime = GetConvertedTime(DateTime.Parse(Childitem.DateTime.ToString()));

            Logs.Add(new Models.Logging()
            {
                Date = ConvertedTime,
                Description = Childitem.Description,
                ID = Childitem.ID,
                Reference = Childitem.Reference,
                Response = Childitem.Response,
                Time = String.Format("{0:h:mm tt}", ConvertedTime),
                Type = Childitem.Type
            });

        }
    }

    return View(Logs);
}

private DateTime GetConvertedTime(DateTime dateTime)
{
    DateTime utcDateTime = dateTime.ToUniversalTime();

    string nzTimeZoneKey = "Pakistan Standard Time";
    TimeZoneInfo nzTimeZone = TimeZoneInfo.FindSystemTimeZoneById(nzTimeZoneKey);
    DateTime nzDateTime = TimeZoneInfo.ConvertTimeFromUtc(utcDateTime, nzTimeZone);

    return nzDateTime;
}

登录控制器

 [HttpPost]

public ActionResult Login(LoginModel model, string returnUrl)
{
    if (ModelState.IsValid && AuthorizeUser(model.UserName, model.Password))
    {
        Session["sessionUserId"] = model.UserName;

        return RedirectToAction("firstRun", "Home");
    }

    // If we got this far, something failed, redisplay form
    ModelState.AddModelError("", "The user name or password provided is incorrect.");
    return View(model);
}

0 个答案:

没有答案