با سلام
لطفا راهنمایی کنید اورژانسی هست
من کدهای زیر رو روی سیستم لوکال اجرا میکنم کار میکنن ارسال میشن ولی وقتی روی هاست آپلود میکنم اجرا نمیشن نه خطا میده نه چیزی کار نمیکنه خیلی ممنون میشم راهنماییم کنید.
$.ajax({
url: "/Admin/add",
data:
function () {
var data = new FormData();
data.append("IdAds", id1);
data.append("Title", jQuery("#Ads_Title").val());
data.append("IdGroupJob", jQuery("#Ads_IdGroupJob").val());
data.append("IdJob", jQuery("#Ads_IdJob").val());
data.append("Roww", jQuery("#Ads_Roww").val());
data.append("R_l", jQuery("#Ads_R_l").val());
data.append("DateStart", jQuery("#Ads_DateStart").val());
data.append("DateEnd", jQuery("#Ads_DateEnd").val());
data.append("UploadImage1", jQuery("#UploadImage1").get(0).files[0]);
return data;
}(),
contentType: false,
processData: false,
type: "Post",
dataType: "Json",
success: function (result) {
if (result.Success) {
table.ajax.reload(null, false);
setTimeout(function () {
$.noty.closeAll();
}, 2000);
if (read == 1) {
read = 0;
$("#demo").collapse("hide");
FTT();
setTimeout(function () {
$.noty.closeAll();
}, 2000);
}
}
eval(result.Script);
}
});
کدهای کنترلر
public ActionResult add(Tbl_Adss Ads, HttpPostedFileBase data)
{
AdsRepository blProduct = new AdsRepository();
if (ModelState.IsValid)
{
var pic = System.Web.HttpContext.Current.Request.Files["UploadImage1"];
HttpPostedFileBase filebase = new HttpPostedFileWrapper(pic);
var allowedExtensions = new[] { ".Jpg", ".png", ".jpg", ".jpeg" };
var ext = Path.GetExtension(filebase.FileName);
if (allowedExtensions.Contains(ext)) //check what type of extension
{
string fileName = Path.GetFileName(filebase.FileName);
string path = Path.Combine(Server.MapPath("../Files/UploadImages/"), fileName);
Ads.Imagee = "../Files/UploadImages/" + filebase.FileName;
filebase.SaveAs(path);
}
else
{
return MessageBox.Show("عکس را وارد کنید", MessageType.Error);
}
if (blProduct.Add(Ads))
{
return Json(new JsonData()
{
Script = MessageBox.Show("با موفقیت اضافه شد", MessageType.Success).Script,
Success = true,
});
}
else
{
//نا موفق
return Json(new JsonData
{
Script = MessageBox.Show("اضافه نشد", MessageType.Error).Script,
Success = false,
Html = ""
});
}
}
else
{
//خطا مقداری
return Json(new JsonData
{
Script = MessageBox.Show(ModelState.GetErrors(), MessageType.Warning).Script,
Success = false,
Html = ""
});
}
}