C#ASP.NET MVC 5 ajax.beginform无法上传文件

时间:2019-02-26 17:52:31

标签: c# asp.net-mvc

我正在尝试在ASP.NET MVC 5.2中使用Ajax.BeginForm()上传文件。

查看:

@model EventsImages
@using (Ajax.BeginForm("Create", "EventsImages", new AjaxOptions { HttpMethod = "POST", OnComplete = "completeForm(xhr, status,'listDialog1')" }, new { enctype = "multipart/form-data", @class = "form", @role = "form" }))
    {
       <div class="col-md-12 col-sm-12">
          @Html.AntiForgeryToken()
          ...
          <input type="file" id="upload" name="upload" />
          <input type="submit" value="Create" class="btn" />

控制器:

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(EventsImages eventsImages, HttpPostedFileBase upload)
{
    if (ModelState.IsValid)
    { 

问题是HttpPostedFileBase上载始终为空。

我知道这个问题已经提到过几次了,但是我找不到解决方案或解决方法。

0 个答案:

没有答案