gpt4 book ai didi

c# - mvc3 将数据从 View 传递到 Controller 时出现问题

转载 作者:太空狗 更新时间:2023-10-29 23:17:47 25 4
gpt4 key购买 nike

我正在使用 mvcContrib 生成一个网格,以允许用户通过键入搜索数据来过滤数据。在我的索引 View 中呈现了几个局部 View :

这是处理搜索的部分 View :

@model CRMNPS.Models.PagedViewModel<CRMNPS.Models.NPSProcessed>
@using (Html.BeginForm("Index", "Home", FormMethod.Get))
{

<label>
Model Number:&nbsp;&nbsp; @Html.TextBox("searchWord" )
<br /><br />From Date:&nbsp;&nbsp;&nbsp; @Html.EditorFor(m => m.FromDate)
</label>
<label>
<Br /><br />To Date:&nbsp;&nbsp;&nbsp; @Html.EditorFor(m => m.ToDate)
</label>
<label>
<br /><br />&nbsp;&nbsp;<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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com