Joe*_*itz 5 c# controller asp.net-mvc-3
我正在使用mvcContrib生成网格,以允许用户通过键入搜索数据来过滤数据。我的索引视图中呈现了几个局部视图:
这是处理搜索的局部视图:
@model CRMNPS.Models.PagedViewModel<CRMNPS.Models.NPSProcessed>
@using (Html.BeginForm("Index", "Home", FormMethod.Get))
{
<label>
Model Number: @Html.TextBox("searchWord" )
<br /><br />From Date: @Html.EditorFor(m => m.FromDate)
</label>
<label>
<Br /><br />To Date: @Html.EditorFor(m => m.ToDate)
</label>
<label>
<br /><br /> <input class="button" value="Search" type="submit" />
<br />
</label>
}
Run Code Online (Sandbox Code Playgroud)
这是我的索引视图:
@model PagedViewModel <CRMNPS.Models.NPSProcessed>
@{
ViewBag.Title = "CRM Processed List";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Processed List</h2>
@{Html.RenderPartial("SearchBox");}
@{Html.RenderPartial("Pager", Model.PagedList);}
@Html.Grid(Model.PagedList).AutoGenerateColumns().Columns(column =>{
column.For(x => Html.ActionQueryLink(x.ModelNumber, "Edit", new { id = x.Id
})).Named("Id").InsertAt(1);
}).Sort(Model.GridSortOptions).Attributes(@class => "grid-style")
@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { FromDate = Model.FromDate, ToDate = Model.ToDate, SearchWord = Model.SearchWord }))
{
<p>
<input class="button" value="Export to Excel" type="submit" />
</p>
}
Run Code Online (Sandbox Code Playgroud)
在索引视图的底部,我在Html.BeginForm中还有一个带有Formmethod.Post的提交。
调用此视图的Index ActionResult传递一个带有搜索条件的视图模型和一个mvcContrib使用的IQueryable对象。
当用户按下“导出到Excel”按钮时,我想将选定的值传递回Index actionresult HttpPost控制器。(FromDate,ToDate和SearchWord)
FromDate,ToDate和SearchWord值始终返回null。
我对MVC相当陌生,因此欢迎提出任何建设性意见。
谢谢
乔
因为它们不是您发布的表单 - (导出到 Excel 采用单独的表单)。输入
从日期、到日期和搜索词
处于第一种形式(在部分视图中)。因此这些值不会显示在控制器中(因为它们不是 http post 的一部分)。如果您想看到所有这些值被传递回控制器,它们应该在 1 之下
Html.BeginForm