Asp. NET image upload (with jquery.from.js plugin)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.