将输入文件Ajax发送到ASP.NET MVC控制器

问题描述

代码ajax

$.ajax({
    type: "POST",url: "/Admin/AddItem",data: {
        title: title.value,desc: desc.value,quantity: quantity.value,brand: brand.value,cat: cat.value,certify: certify.value,gold: gold.value,gold_wt: gold_wt.value,stone: stone.value,stone_wt: stone_wt.value,dim: dim.value,dim_wt: dim_wt.value,other: other.value,image: image.files[0],price: price
    },dataType: "json",success: function (response) {
        alert('Succes!'); window.location.href = '/Admin/Item';
    }
});

image.files[0] =>控制器获取HttpPostedFileBase image

代码控制器

public void AddItem(String title,String desc,int quantity,int brand,int cat,int certify,int gold,float gold_wt,int stone,float stone_wt,int dim,float dim_wt,float other,HttpPostedFileBase image,float price)
{
    String path = "";

    if (image != null)        
    {
        path = Path.Combine(Server.MapPath("~/Content/Products"),Path.GetFileName(image.FileName));
        image.SaveAs(path);
    }
}

我想将图像从Ajax传递到控制器。我怎么弄出来的?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)