jquery代码
$(document).ready(function () {
$("#ContentPlaceHolder1_btnsubmit").click(function () {
var name = $("#ContentPlaceHolder1_txtname").val();
var course = $("#ContentPlaceHolder1_txtcourse").val();
var qualififcation = $("#ContentPlaceHolder1_txtqualification").val();
var company = $("#ContentPlaceHolder1_txtcomp").val();
var salary = $("#ContentPlaceHolder1_txtsal").val();
var role = $("#ContentPlaceHolder1_txtrole").val();
var description = $("#ContentPlaceHolder1_txtdesc").val();
var status = $("#ContentPlaceHolder1_ddstatus").val();
var image = $("#ContentPlaceHolder1_FileUpload1").val();
var url = "ajaxhandler.aspx?taskname=insertstudent";
$.post(url,
{
name: name, course: course, qualififcation: qualififcation, company: company, salary: salary,
role: role, description: description, status: status, image: image
},
function (data, status) {
if (status == "success") {
alert("student inserted");
}
}
)
});
});
ajaxhandler页面代码
int image = Convert.ToInt32( Request.Form["image"]);
int a = BLL.studentbll.insertstudent(name,course,qualification,company,salary,role,description, status);
if (image>0 )
{
string ext = System.IO.Path.GetExtension(image.FileName);
image.SaveAs(Server.MapPath("images\\" + Convert.ToString(a) + ".jpg"));
}
存储图像时似乎出错 image.filename无法访问 如何使用ajax或jquery
将图像保存在asp.net的文件夹中答案 0 :(得分:1)
这里ajax没有传递图像文件所以你可以通常在ajax处理程序中检索文件
string filename = Path.GetFileName(fileuploadimages.PostedFile.FileName);
以下是参考站点链接:
http://www.aspdotnet-suresh.com/2011/03/how-to-save-images-into-folder-and.html