【发布时间】:2016-11-21 12:12:33
【问题描述】:
情况是这样的: 我有一个表单,当我单击提交按钮时,它正在发送带有剑道上传控件的文件,并且控制器的方法操作正在使用 HttpPostedFileBase 的参数中接收该文件。
这是我的 HTML 代码:
@using (Html.BeginForm("ConfirmarOposicion", "Gestion", FormMethod.Post, new { @id = "Frm-login", role = "form", @class = "form-horizontal" }))
{
@(Html.Kendo().Upload()
.Name("files")
)
<button class="btn btn-success" type="submit" id="confirm" >Confirm</button>
}
这是我的控制器:
public async Task<ActionResult> ConfirmarOposicion(IEnumerable<HttpPostedFileBase> files)
{
// Here the parameter files is not null..
}
到目前为止一切正常。问题是当我尝试将更多值作为参数发送到控制器的同一方法中时。 我要发送的其他值是一个数组,另一个是一个数字。 我尝试在 javaScript 中使用 ajax 发送这两个值。
这是我尝试发送另外两个值时的 javaScript 代码:
$("#confirm").click(function () {
var numMarca = $("#numMarca").val()
var idsToSend = [];
var grid = $("#Grid2").data("kendoGrid")
var ds = grid.dataSource.view();
for (var i = 0; i < ds.length; i++) {
var row = grid.table.find("tr[data-uid='" + ds[i].uid + "']");
var checkbox = $(row).find(".checkbox");
if (checkbox.is(":checked")) {
idsToSend.push(ds[i].DescMarca);
idsToSend.push(ds[i].IntencionOposicion = 1);
} else {
idsToSend.push(ds[i].DescMarca);
}
}
$.ajax({
url: '@Url.Action("ConfirmarOposicion", "Gestion")',
data: { ids: idsToSend, marca: numMarca },
type: 'POST',
dataType: "json",
success: function (data) {
}
});
当我单击提交按钮时,我在发送输入文件的同一控制器中发送这两个值。
这是我现在的控制器:
public async Task<ActionResult> ConfirmarOposicion(IEnumerable<HttpPostedFileBase> files, string[] ids, string marca)
{
// here the array ids and the value of marca is not null, but the parameter files it is null
}
这就是我遇到的问题。 我需要在控制器的相同方法操作中发送所有这些值。 我该怎么做?
【问题讨论】:
-
所以你的意思是说在你添加了其他参数之后你不再接收文件了?
-
是的,文件现在是空的。
-
给了你我的答案。
标签: javascript jquery ajax asp.net-mvc kendo-upload