我正在使用 mvcContrib 生成一个网格,以允许用户通过键入搜索数据来过滤数据。在我的索引 View 中呈现了几个局部 View :
这是处理搜索的部分 View :
@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>
}
这是我的索引 View :
@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>
}
在索引 View 的底部,我在 Html.BeginForm 中有另一个带有 Formmethod.Post 的提交。
调用此 View 的 Index ActionResult 传递带有搜索条件的 View 模型和 mvcContrib 使用的 IQueryable 对象。
当用户按下导出到 Excel 按钮时,我想将选定的值传递回 Index actionresult HttpPost Controller 。 (FromDate, ToDate 和 SearchWord)
FromDate、ToDate 和 SearchWord 值总是返回 null。
我是 MVC 的新手,所以欢迎任何建设性的意见。
谢谢
乔
最佳答案
因为它们不是您发布的形式 - (导出到 Excel 是单独的形式)。 输入
FromDate, ToDate and SearchWord
都是第一种形式(在局部 View 中)。所以这些值不会出现在 Controller 中(因为它们不是 http post 的一部分)。 如果你想看到所有这些值都被传回 Controller ,它们应该在一个之下
Html.BeginForm
关于c# - mvc3 将数据从 View 传递到 Controller 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7519004/