Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在jquery选项卡中实现多文件上传控制_Jquery_Asp.net Mvc_Tabs_File Upload - Fatal编程技术网

在jquery选项卡中实现多文件上传控制

在jquery选项卡中实现多文件上传控制,jquery,asp.net-mvc,tabs,file-upload,Jquery,Asp.net Mvc,Tabs,File Upload,我使用asp.NETMVC2。我有三个jquery选项卡。在三个选项卡中的每一个选项卡中,我都希望上载多个文件并保存到服务器上。实现这一点的最佳方法是什么?我还想用ajax文件上传实现ajax基本文件上传。对于多个文件上传,一个快速的google显示。和AJAX文件上传。对于多个文件上传,一个快速的google显示。基于flash,功能更强大,因为它可以处理其他表单元素。有很多jquery插件可以满足您的需求。我建议在谷歌上搜索“jqueryajax上传”,并尝试提供给您的不同选项,看看哪个选项

我使用asp.NETMVC2。我有三个jquery选项卡。在三个选项卡中的每一个选项卡中,我都希望上载多个文件并保存到服务器上。实现这一点的最佳方法是什么?我还想用ajax文件上传实现ajax基本文件上传。对于多个文件上传,一个快速的google显示。

和AJAX文件上传。对于多个文件上传,一个快速的google显示。

基于flash,功能更强大,因为它可以处理其他表单元素。有很多jquery插件可以满足您的需求。我建议在谷歌上搜索“jqueryajax上传”,并尝试提供给您的不同选项,看看哪个选项适合您的项目

编辑

下面是我在使用表单插件返回文本区域中的响应时使用的代码

以下是上传操作:

public FileUploadJSONResult Upload()
    {
        FileUploadJSONResult result;

        try
        {
            if (Request.Files.Count > 0)
            {
                // Save uploaded file here
                AttachmentServices attachmentServices = new AttachmentServices();
                IAttachment attachment = attachmentServices.UploadFile(Request.Files[0]);

                // Wrap the data in a textarea as required by the form plugin, but return it using JSON
                result = new FileUploadJSONResult()
                {
                    Data = new
                    {
                        FileName = attachment.FileName,
                        ErrorMessage = string.Empty
                    }
                };
            }
            else
            {
                result = new FileUploadJSONResult
                {
                    Data = new
                    {
                        FileName = string.Empty,
                        ErrorMessage = "No file to upload. Please select a file to upload."
                    }
                };
            }
        }
        catch (Exception e)
        {
            LogError(logger, e, null);

            Exception root = e;
            while ((root.InnerException) != null)
            {
                root = root.InnerException;
            }

            result = new FileUploadJSONResult
            {
                Data = new
                {
                    FileName = string.Empty,
                    ErrorMessage = root.Message
                }
            };
        }

        return result;
    }
然后是
文件上传jsonresult

public class FileUploadJSONResult : JsonResult
{  
    /// <summary>
    /// The following explanation of this code is from http://www.malsup.com/jquery/form:
    /// 
    ///  Since it is not possible to upload files using the browser's XMLHttpRequest object, the Form Plugin 
    ///  uses a hidden iframe element to help with the task. This is a common technique, but it has inherent limitations. 
    ///  The iframe element is used as the target of the form's submit operation which means that the server response is 
    ///  written to the iframe. This is fine if the response type is HTML or XML, but doesn't work as well if the 
    ///  response type is script or JSON, both of which often contain characters that need to be repesented using 
    ///  entity references when found in HTML markup.
    ///  To account for the challenges of script and JSON responses, the Form Plugin allows these responses to be 
    ///  embedded in a textarea element and it is recommended that you do so for these response types when used in 
    ///  conjuction with file uploads. Please note, however, that if a file has not been selected by the user for the 
    ///  file input then the request uses normal XHR to submit the form (not an iframe). This puts the burden on your 
    ///  server code to know when to use a textarea and when not to. If you like, you can use the iframe option of the 
    ///  plugin to force it to always use an iframe mode and then your server can always embed the response in a textarea. 
    /// </summary>
    /// <param name="context">Controller context</param>
    public override void ExecuteResult(ControllerContext context)
    {
        this.ContentType = "text/html";
        context.HttpContext.Response.Write("<textarea>");
        base.ExecuteResult(context);
        context.HttpContext.Response.Write("</textarea>");
    }
}
它基于flash,功能更强大一些,因为它可以使用其他表单元素。有很多jquery插件可以满足您的需求。我建议在谷歌上搜索“jqueryajax上传”,并尝试提供给您的不同选项,看看哪个选项适合您的项目

编辑

下面是我在使用表单插件返回文本区域中的响应时使用的代码

以下是上传操作:

public FileUploadJSONResult Upload()
    {
        FileUploadJSONResult result;

        try
        {
            if (Request.Files.Count > 0)
            {
                // Save uploaded file here
                AttachmentServices attachmentServices = new AttachmentServices();
                IAttachment attachment = attachmentServices.UploadFile(Request.Files[0]);

                // Wrap the data in a textarea as required by the form plugin, but return it using JSON
                result = new FileUploadJSONResult()
                {
                    Data = new
                    {
                        FileName = attachment.FileName,
                        ErrorMessage = string.Empty
                    }
                };
            }
            else
            {
                result = new FileUploadJSONResult
                {
                    Data = new
                    {
                        FileName = string.Empty,
                        ErrorMessage = "No file to upload. Please select a file to upload."
                    }
                };
            }
        }
        catch (Exception e)
        {
            LogError(logger, e, null);

            Exception root = e;
            while ((root.InnerException) != null)
            {
                root = root.InnerException;
            }

            result = new FileUploadJSONResult
            {
                Data = new
                {
                    FileName = string.Empty,
                    ErrorMessage = root.Message
                }
            };
        }

        return result;
    }
然后是
文件上传jsonresult

public class FileUploadJSONResult : JsonResult
{  
    /// <summary>
    /// The following explanation of this code is from http://www.malsup.com/jquery/form:
    /// 
    ///  Since it is not possible to upload files using the browser's XMLHttpRequest object, the Form Plugin 
    ///  uses a hidden iframe element to help with the task. This is a common technique, but it has inherent limitations. 
    ///  The iframe element is used as the target of the form's submit operation which means that the server response is 
    ///  written to the iframe. This is fine if the response type is HTML or XML, but doesn't work as well if the 
    ///  response type is script or JSON, both of which often contain characters that need to be repesented using 
    ///  entity references when found in HTML markup.
    ///  To account for the challenges of script and JSON responses, the Form Plugin allows these responses to be 
    ///  embedded in a textarea element and it is recommended that you do so for these response types when used in 
    ///  conjuction with file uploads. Please note, however, that if a file has not been selected by the user for the 
    ///  file input then the request uses normal XHR to submit the form (not an iframe). This puts the burden on your 
    ///  server code to know when to use a textarea and when not to. If you like, you can use the iframe option of the 
    ///  plugin to force it to always use an iframe mode and then your server can always embed the response in a textarea. 
    /// </summary>
    /// <param name="context">Controller context</param>
    public override void ExecuteResult(ControllerContext context)
    {
        this.ContentType = "text/html";
        context.HttpContext.Response.Write("<textarea>");
        base.ExecuteResult(context);
        context.HttpContext.Response.Write("</textarea>");
    }
}

如果你需要实际的示例代码,你必须提供更多关于设置的详细信息,或者发布一些代码。如果你需要实际的示例代码,你必须提供更多关于设置的详细信息,或者发布一些代码。我觉得表单插件很有趣,我想知道如何在asp.net mvc 2中的html文本区域嵌入ajax响应。任何想法都取决于Flash Player:-/我觉得表单插件很有趣,我想知道如何在asp.net mvc 2中的html文本区域嵌入ajax响应。任何想法都取决于Flash播放器:-/