使用Ajax.BeginForm异空参数Html.BeginForm [英] Null parameter using Ajax.BeginForm iso Html.BeginForm

查看:180
本文介绍了使用Ajax.BeginForm异空参数Html.BeginForm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个控制器方法处理文件上传:

Got a controller method handling a file upload:

AcceptVerbs(HttpVerbs.Post)]
public ActionResult FileUpload(int id, HttpPostedFileBase uploadFile)
{
    if (uploadFile != null && uploadFile.ContentLength > 0 && ...)
    ...
}

当我使用Html.BeginForm这一切工作正常。更换用Ajax.BeginForm结果Html.BeginForm在uploadFile空值(DE上述方法的第二个参数):

When I use Html.BeginForm it all works fine. Replacing the Html.BeginForm with Ajax.BeginForm results in a null value for uploadFile (de 2nd parameter of the method above):

<div id="ajaxDocumentUpload">
@{ using (Ajax.BeginForm("FileUpload", "ProjectDocument", FormMethod.Post, 
           new AjaxOptions { OnSuccess = "UploadSuccess" }, 
           new { enctype = "multipart/form-data" }))
  {
    <div>
        <input type=file accept="image/gif, image/jpeg" name="uploadFile">     
    </div>
    <div>
        <input type="hidden" name="id" id="id" value="@Model.ProjectId"/>
    </div>

    <input id=btnUpdateAttachment type=submit value="Upload">
  } 
}
</div>

任何想法有什么不好?在此先感谢您的帮助!

Any idea what is wrong? Thanks in advance for any help!

推荐答案

原来是一个安全问题,看的使用Ajax调用MVC3 的答案上传文件。

Turns out to be a security problem, look Upload file using ajax call MVC3 for the answer.

这篇关于使用Ajax.BeginForm异空参数Html.BeginForm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆