Front:
Js:
function Ajaxkoubeishopedit () {
var options = {
DataType: "JSON",
Success:function (data) {
alert (data);
},
Error:function (XMLHttpRequest, Textstatus, Errorthrown) {
Console.log (Textstatus);
Console.log (Errorthrown);
}
};
$ ("#ShopForm"). Ajaxsubmit (options);
}
Html:
<form class= "Form-horizontal" id= "Shopform" action= "Your controller/ajaxkoubeishopedit" method= "post" enctype= "multipart/ Form-data ">
<input type= "File" Name= "productimg" class= "FileData"/>
<input type= "File" Name= "productimg" class= "FileData"/>
</form>
Back end:
<summary>
Word of mouth store-add
</summary>
<param name= "Upimg" ></param>
<param name= "entity" ></param>
<returns></returns>
[HttpPost]
public string Ajaxkoubeishopedit (Koubeishopmodel entity)
{
StringBuilder sqlstr = new StringBuilder ();
TimeSpan timespan = (Datetime.now-timezone.currenttimezone.tolocaltime (New System.DateTime (1970, 1, 1)));
Random random = new random ();
Jobject resultjsonerr = new Jobject ();
Modify Operation
#region Add Files
String filephysicalpath = @ "d:/yyyy/";
String mainimgname = "";
Detailed picture Path
if (Request.Files.Count! = 0)
{
Mainimgname = Filephysicalpath + mainimgname;
Try
{
for (int i = 0; i < request.files.count;i++)
{
HttpPostedFileBase uploadfile = request.files[i] as HttpPostedFileBase;
if (uploadfile! = null && uploadfile.contentlength > 0)
{
if (i==0)//First image
// {
HTML top to bottom load, file input
// }
Random Name
Long t2 = (long) timespan.totalseconds;
int n2 = random. Next (10000, 99999);
string extension = Path.getextension (uploadfile.filename);
String imglistname = t2 + "" + n2 + extension;
var path = Path.Combine (Filephysicalpath, imglistname);
Uploadfile.saveas (path);
}
}
}
catch (Exception ex)
{
Resultjsonerr.add ("state",-1);
Return "Add Failed";
}
}
Return "Add success";
}
Asp. NET image upload (with jquery.from.js plugin)