问题描述
当我尝试添加Ajax
并将其他数据传递到动作控制器时,我的模型参数受到影响,该值为null,而我的Ajax
参数具有一个值。
我不认为这是因为我使用的是Html.beginform('index','payable')
,而我使用的是Ajax
url: '@Url.Action("index","payable")',
和相同的ActionResult.
您可以在下面看到参考。
@using (Html.BeginForm("index","payable",FormMethod.Post,new { enctype = "multipart/form-data" }))<div class="col-md-2">
<div class="form-group">
@Html.LabelFor(x => x.Amount,new { @class = "form-label" })
@Html.TextBoxFor(x => x.Amount,new { @class = "form-control" })
</div>
</div>
<div class="col-md-2">
<div class="form-group">
@Html.LabelFor(x => x.ImagePath,new { @class = "form-label" })
<input type="file" name="file" id="files" />
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<button type="submit" id="btnUpload" class="btn btn-primary btn-sm" onclick="saveSelected()"><i class="fas fa-save"></i> Submit Payment</button>
</div>
</div>{
我的Ajax
function saveSelected() {
$.ajax({
url: '@Url.Action("index",type: 'POST',data: { ids: ids },traditional: true,success: function (data) {
alert("success");
}
});
}
我的控制器
public ActionResult Index(PayableFormModel model,HttpPostedFileBase file,int[] ids)
{
return View();
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)