[英]Send complex object from view to MVC action as none ajax call
I'm working on an ASP.NET MVC web application.我正在开发一个ASP.NET MVC Web 应用程序。 There is a view with a bunch of search filters and there is also a grid in the middle of the page that represents the result of the search.
有一个带有一堆搜索过滤器的视图,页面中间还有一个表示搜索结果的网格。
End-user set value for the search filter and when search button clicked an ajax call returns the values that will rebind the gird.最终用户为搜索过滤器设置值,当单击搜索按钮时,ajax 调用将返回将重新绑定网格的值。 every row in the grid represents '
ItemId
' and ' version
' which could be selected by the checkbox.网格中的每一行都代表“
ItemId
”和“ version
”,它们可以通过复选框选择。
At the end when the user clicks on " Detail report
" we need to redirect the user to another page(view).最后,当用户点击“
Detail report
”时,我们需要将用户重定向到另一个页面(视图)。
I need to pass the selected search filters and the grid selected rows values as an array like this (ItemIds[] and Versions[])
to the " Detail
" action.我需要将选定的搜索过滤器和网格选定的行值作为这样的数组
(ItemIds[] and Versions[])
传递给“ Detail
”操作。
So, to make the question clear.所以,把问题说清楚。 I need to pass the below values to the action :
我需要将以下值传递给操作:
Unfortunately, I can not pass the parameters to the action.不幸的是,我无法将参数传递给操作。 I got null
我得到了空
I can not call the action as ajax call When i use当我使用时,我不能将操作称为 ajax 调用
View ( Index.cshtml
)查看 (
Index.cshtml
)
function prepareSelectedInfos() {
var formValues = $('#form').serializeFormToObject();
var gridValues = GetGridSelectedValues();
var dto = {
FormFilters: formValues,
ItemIds : gridValues.ItemIds,
Versions : gridValues.Versions
}
return dto;
}
$('#lnkDetailReport').click(function () {
var gridValues = GetGridSelectedValues();
var url = '/Report/Controller/Detail/';
var dto = prepareSelectedInfos();
window.open(url + dto, '_blank');
});
Controller控制器
public ActionResult Detail(ModelVersionStatisticalDetailDto data)
{
//create a ViewModel according to the incoming data
var viewModel = ;
return View(viewModel);
}
Model模型
public class ModelVersionStatisticalDetailDto
{
public ModelVersionStatisticalReportDto FormFilters { get; set; }
public int [] ItemIds { get; set; }
public string[] Versions { get; set; }
}
I need to have the view prepared values in the Detail action我需要在 Detail 操作中准备好视图值
To the best of my recollection, it is not possible to perform a redirect after having post a complex object in ajax call (with the same posted parameters).据我所知,在 ajax 调用中发布复杂对象(使用相同的发布参数)后,无法执行重定向。 In order to perform your desired operation, you can choose a solution from below.
为了执行您想要的操作,您可以从下面选择一个解决方案。
Partial View
Partial View
替换Detail action 的响应
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.