[英]mvc4 paging on partial view
我已经创建了人事登记表。 在此表单中,我添加了一个显示人员列表的partial view
。 我在此表单上添加了分页。 现在,我想实现搜索功能。
我的表格如下
在这里,我想实现搜索功能。 但问题是我在表单上有两个按钮,即“ Create
和“ 搜索” 。 当我单击搜索按钮时,它为我提供了register.cshtml格式的必填字段验证。
这是我的register.cshtml代码
@model WebLess.Models.PersonModel
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.firstName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.firstName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.firstName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.lastName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.lastName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.lastName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.email, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.email, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.email, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
<div class="form-group">
@if (ViewBag.Message != null)
{
<span class="text-success">@ViewBag.Message</span>
}
</div>
<div class="form-group">
@Html.Partial("list", Model.listOfPerson)
</div>
</div>
}
这是我的list.cshtml
。
@model PagedList.IPagedList<WebLess.Models.PersonModel>
@using PagedList.Mvc;
<link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" />
@using (Html.BeginForm("Register", "Person", FormMethod.Get))
{
<p>
Find by name: @Html.TextBox("SearchString", ViewBag.CurrentFilter as string)
<input type="submit" value="Search" />
</p>
}
<table class="table">
<tr>
<th>
First name
</th>
<th>
Last name
</th>
<th>
E-mail Address
</th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.firstName)
</td>
<td>
@Html.DisplayFor(modelItem => item.lastName)
</td>
<td>
@Html.DisplayFor(modelItem => item.email)
</td>
</tr>
}
</table>
<br />
Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
@Html.PagedListPager(Model, page => Url.Action("Register",
new { page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter }))
如何实现搜索功能?
您可以将列表部分视图移到创建表单之外,然后将搜索功能放入列表部分视图内的自己的表单中(它们还是完全分开的,因此应该分开)。 这样就可以实现您想要的。
使用两个单独的形式而不是嵌套形式
就像史蒂夫(Steve)所说的“将列表局部视图移到创建表单之外”会导致分成两个单独的表单,而不是另一个表单中的一个表单
喜欢
@using (Html.BeginForm())
{
}
@using (Html.BeginForm("Register", "Person", FormMethod.Get))
{
}
代替( 不允许表单中的表单 )
@using (Html.BeginForm())
{
@using (Html.BeginForm("Register", "Person", FormMethod.Get))
{
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.