Image asp.net mvc4中用于创建、编辑和删除的部分视图页面

Image asp.net mvc4中用于创建、编辑和删除的部分视图页面,image,uploading,Image,Uploading,如何在asp.net mvc4中上载图像。图像保存在本地文件夹中,图像路径名保存到数据库。我想说使用Valum的AJAX文件上载程序 我就是这样做的 [HttpGet] public ActionResult PictureUpload() { return View(); } [HttpPost] public ActionResult PictureUpload( string qqfile) { var p

如何在asp.net mvc4中上载图像。图像保存在本地文件夹中,图像路径名保存到数据库。

我想说使用Valum的AJAX文件上载程序

我就是这样做的

 [HttpGet]
    public ActionResult PictureUpload()
    {
        return View();
    }

    [HttpPost]
    public ActionResult PictureUpload( string qqfile)
    {
        var path = Server.MapPath("~/App_data/Files/");
        var file = string.Empty;

        try
        {
            var stream = Request.InputStream;
            if (String.IsNullOrEmpty(Request["qqfile"]))
            {
                // IE
                HttpPostedFileBase postedFile = Request.Files[0];
                if (postedFile != null) stream = postedFile.InputStream;
                file = Path.Combine(path, qqfile);
            }
            else
            {
                //Webkit, Mozilla
                file = Path.Combine(path, qqfile);
            }

            var buffer = new byte[stream.Length];
            stream.Read(buffer, 0, buffer.Length);
            System.IO.File.WriteAllBytes(file, buffer);
        }
        catch (Exception ex)
        {
            return Json(new { success = false, message = ex.Message }, "application/json");
        }

        return Json(new { success = true }, "text/html");
    }
**这个给定的HTML和Javascript需要从Valums网站上传JS文件和css文件**

索引


请启用JavaScript以使用文件上载程序

var uploader=new qq.FileUploader({ //传递dom节点(对于jQuery用户,例如$(选择器)[0] 元素:document.getElementById('file-uploader'), //服务器端上载脚本的路径 操作:'/FileUpload/File', onComplete:函数(数据){ 警报(数据); }, });
希望这会有所帮助

<div id="file-uploader">       
    <noscript>          
        <p>Please enable JavaScript to use file uploader.</p>
        <!-- or put a simple form for upload here -->
    </noscript>         
</div>
<script src="~/Scripts/fileuploader.js"></script>
<script type="text/javascript">

    var uploader = new qq.FileUploader({
        // pass the dom node (ex. $(selector)[0] for jQuery users)
        element: document.getElementById('file-uploader'),
        // path to server-side upload script
        action: '/FileUpload/File',
        onComplete: function(data) {
            alert(data);
        },
    });
</script>