Hello I have html text in this html text there are two img(there may be more than 2 img) I want to take this img's src and change it. Change operation will be in server side so. In js I wrote
$(content).find('img').each(function () {
var src = $(this).attr('src');
if (src !== "" || src != null)
//var result = content.replace(src, changeImageUrls(src));
});
content is html string. With this code I find src of img but after this I will send it to controller.
function changeImageUrls(urls) {
console.log(urls);
var newurl = "";
$.ajax({
type: 'POST',
url: '@Url.Action("Upload", "Media")',
data: JSON.stringify({
url: urls
}),
async: false,
success: function (data) {
if (data.Status !== 200) {
toastr.warning('@Resources.Resource.Error_Unexpected');
return;
}
if (data.Result === "FILE_COULDNT_SAVED") {
toastr.warning('Sayfa tasarımı kaydedilemedi.');
return;
}
newurl = data.Result;
console.log("Yeni url verildi");
},
error: function (error) {
toastr.warning('@Resources.Resource.Error_Unexpected');
return;
}
});
return newurl;
}
I wrote this function two post data to controller.
[HttpPost]
public ActionResult Upload(string url)
{
if (string.IsNullOrEmpty(url))
return Content(Serialization.JsonSerialize(new { Status = 400 }));
return Content(Serialization.JsonSerialize(new { Status = 200, Result = MediaRepository.Upload(url) }));
}
When I post to controller , controller get url always null.I couldn't find the problem. Thanks in advance