これが私が達成したい機能です。参照番号を取得するテキストボックスが必要であり、送信すると、グリッドはその特定の参照番号のレコードを表示する必要があります。デフォルトでは、グリッドが最初にロードされるとき、レコードはありません。[すべて表示] ボタンを押すと、グリッドにデータベース内のすべてのレコードが表示されます。
私はすべてを達成しましたが、問題は、特定の参照番号を検索すると、その特定の番号のレコードが表示されますが、ページングが正しく機能しないことです。適切なページ数が表示されますが、クリックするとページ番号「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);
}