上传是将jquery.unobtrusive-ajax.js参考后空 [英] Upload is null after adding jquery.unobtrusive-ajax.js reference

查看:247
本文介绍了上传是将jquery.unobtrusive-ajax.js参考后空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我不是指 jquery.unobtrusive-ajax.js 我可以在帖子的附件。如果我指的是它给了我零。

If I don't refer jquery.unobtrusive-ajax.js I can get attachment on Post. If I refer it It's giving me null.

<script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>


@using (Ajax.BeginForm("Index", "ContactSubmission", new AjaxOptions{ InsertionMode = InsertionMode.Replace, HttpMethod = "POST", OnSuccess = "updateSuccess" },
     new { enctype = "multipart/form-data",@class = "form-horizontal", role = "form" }))
      {
               ///code here

}

[HttpPost]
public JsonResult Index(Contact contact)
{
    if (ModelState.IsValid)
    {
       if (contact != null)
       {
         string attachment = string.Empty;
         // HttpPostedFileBase Attachment
         if (contact.Attachment != null) attachment = SaveFile(contact.Attachment); 
                ......

如何来处理呢?

How to handle this?

推荐答案

如果您不引用 jquery.unobtrusive-ajax.js ,你没有得到的 AJAX 的形式,而是一个普通的HTML表单。如果你这样做,我想表单工作正常,但不能上载与它的文件,如AJAX不允许的multipart / form-data的加密类型。

If you don't refer jquery.unobtrusive-ajax.js, you don't get the ajax form, but a regular HTML form. And if you do, I suppose the form works fine, but it is not possible to upload a file with it, as ajax does not allow multipart/form-data enctype.

您可以使用HTML 5文件API(使用文件从Web应用程序)或上传的jQuery插件。

You can use HTML 5 File API (Using files from web applications) or jQuery upload plugins.

这篇关于上传是将jquery.unobtrusive-ajax.js参考后空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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