从ajax将数组传递给MVC控制器 [英] Pass an array to MVC Controller from ajax
本文介绍了从ajax将数组传递给MVC控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将JS数组传递给MVC控制器。通过使用相同的代码,我能够为API控制器做同样的事情。但是我无法使用MVC控制器做同样的事情。
任何人都可以请帮助
这个是JS方面
Hi,
I am trying to pass a JS array to a MVC Controller. By using the same code i was able to do the same for API Controller. But i am not able to do the same using MVC Controller.
Can anyone please help
This is the JS side
function GetColumnmappingValue() {
var columnMappings = [];
var count = 0;
$('.row').each(function () {
if (count > 0) {
var sourceColumn = "";
var destinationColumn = "";
var sourceColumnIndex = "";
$(this).find(".column").each(function () {
var input = $(this).find("select").each(function (i) {
if (sourceColumn == "") {
sourceColumn = $(this).find("option:selected").text();
sourceColumnIndex = $(this).find("option:selected").val();
}
else {
destinationColumn = $(this).find("option:selected").text();
}
});
});
//if (sourceColumn.toLowerCase() != "select" && destinationColumn.toLowerCase() != "select")
columnMappings.push({ SourceColumnIndex: sourceColumnIndex, SourceColumn: sourceColumn, DestinationColumn: destinationColumn });
}
count++;
});
$.ajax({
type: "POST",
url: "/ExcelImport/SaveMappings",
data: { '': columnMappings },
dataType: "json",
success: function () { alert("Mapping Successful") },
failure: function () { alert("not working..."); }
});
}
这是控制器
and this is the controller
[HttpPost]
public IEnumerable<ColumnMapping> SaveMappings(IEnumerable<ColumnMapping> columnMappings)
{
// do some registration work
CreateXML(columnMappings);
return columnMappings;
}
问题是我得到数组计数,但其中的所有值都为null ..
谢谢
Arjun Menon
The problem is that i am getting the array count , but all values inside it are null ..
Thanks
Arjun Menon
推荐答案
(' 。row')。each( function (){
if (count> 0 ){
var sourceColumn = ;
var destinationColumn = ;
var sourceColumnIndex = ;
('.row').each(function () { if (count > 0) { var sourceColumn = ""; var destinationColumn = ""; var sourceColumnIndex = "";
>
( this )。find( 。column)。each( function (){
< span class =code-keyword> var input =
(this).find(".column").each(function () { var input =
( this )。find( 选择)。each( function (i) {
if (sourceColumn == ){
sourceColumn =
(this).find("select").each(function (i) { if (sourceColumn == "") { sourceColumn =
这篇关于从ajax将数组传递给MVC控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文