获取表单值与MvcPager [英] Getting form values with MvcPager
问题描述
当我选择我的 PagedList中任何页面; T>
的 [HTTPGET]
方法被激活。正因为如此,我不是能够使用 Request.Form.GetValues()
。
When I select any page of my PagedList<T>
the [HttpGet]
method is activated. Because of this, Im not able to use Request.Form.GetValues()
.
我刚才看到的请求
变量到即时窗口,并意识到,我没有看到,我从我有(请求的ID想要的任何值不给我任何屏幕的任何ID值,因为我不是使用POST方法)。
I just saw the Request
variable into the immediate window and realized that I dont see any value that I want from the IDs that I have ( the request dont bring me any value of any ID of the screen, since Im not using the post method).
我得到了一个网格(表),每个记录是一个复选框,分页后,我需要知道至极复选框中的一个字段被启用,以保持它选中(我已经取得了code,以保持它的检查,我只需要知道如何林去看看,如果这些复选框被选中。
I got a grid (table) and one field of each record is a checkbox, after the pagination, I need know wich checkbox is enabled to keep it checked ( I already made the code to keep it checked, I just need to know how Im going to see if those checkboxes are checked.
我已经知道自己的身份证了。
I already know their ID too.
即时通讯使用下列控制生成的复选框:
Im using the following control to generate those checkboxes:
//foreachloop
<%: Html.CheckBox(item.ID.ToString(), item.isChecked)%>
有关我的分页,进出口使用下列内容:
For my pagination, Im using the following:
.aspx的:
&LT;%:Html.Pager(Model.ListaGridPaginada)%>
Aspx: <%: Html.Pager(Model.ListaGridPaginada)%>
这是寻呼机调用以下超负荷:
This pager is a overload that calls the following:
public static MvcHtmlString Pager(this HtmlHelper helper, int totalPageCount, int pageIndex, string actionName, string controllerName,
PagerOptions pagerOptions, string routeName, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes)
{
var builder = new PagerBuilder
(
helper,
actionName,
controllerName,
totalPageCount,
pageIndex,
pagerOptions,
routeName,
routeValues,
htmlAttributes
);
return builder.RenderPager();
}
我调用该方法至极构建这个变量具有以下参数:
I call the method wich constructs this variable with the following parameters:
public static MvcHtmlString Pager<T>(this HtmlHelper helper, PagedList<T> pagedList)
{
if (pagedList == null)
return Pager(helper,null, null);
return Pager(helper, pagedList.TotalPageCount, pagedList.CurrentPageIndex, null, null, null,null, null,null);
}
这pagerHelper是 Webdiyer
This pagerHelper is from Webdiyer
推荐答案
我觉得如果你把它包装的形式,并设置为GET方法,那么它应该通过在所有的表单值进入查询字符串。事情是这样的:
I think if you wrap it in a form and you set the method to GET, then it should pass in all of your form values into the query string. Something like this:
using (Html.BeginForm("Controller", "Action", FormMethod.Get))
{
// grid in here
//foreachloop
<%: Html.CheckBox(item.ID.ToString(), item.isChecked)%>
<input type="submit" value="Save" />
}
当你点击提交按钮,您的查询字符串会是这个样子:
When you click the submit button, your query string will look something like this:
Action?ID1=false&ID2=true&ID2=false
其中,你将看到查询字符串,以确定是否该复选框ID包含如此。见ID1如何=假,但是ID2是真假?这意味着ID1是不加制止,但被ID2检查。
Which, you'll look at the query string to determine if the checkbox ID contains true. See how ID1=false, but ID2 is true and false? That means ID1 was unchecked, but ID2 was checked.
Request.QueryString["ID2"].Contains("True")
如果不适合你,你可以跟踪哪些复选框被把他们选中状态在一个隐藏的价值,并通过周围使用javascript检查。
If that doesn't work for you, you could keep track of which checkboxes are checked with javascript by putting their checked state in a hidden value and passing that around.
这是否帮助任何?
这篇关于获取表单值与MvcPager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!