1

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);
}
4

0 回答 0