如何解决将输入文件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 举报,一经查实,本站将立刻删除。