i have create AJAX function to get img scr now i want to place it in on page
var imgscr='~/content/1.jpg' //geting from ajax
@Url.Content(imgscr); // i am getting error as imgscr not found
public ActionResult Data()
{
List<ImgAudioEntity> listImgAudioEntity = new List<ImgAudioEntity>();
listImgAudioEntity.Add(
new ImgAudioEntity { ImgSrc = "Content/SliderImg/1.jpg", AudioSrc = "~/SliderAudio/1.mp3" }
);
listImgAudioEntity.Add(new ImgAudioEntity { ImgSrc = "Content/SliderImg/2.jpg", AudioSrc = "~/SliderAudio/2.mp3" });
listImgAudioEntity.Add(new ImgAudioEntity { ImgSrc = "Content/SliderImg/3.jpg", AudioSrc = "~/SliderAudio/3.mp3" });
listImgAudioEntity.Add(new ImgAudioEntity { ImgSrc = "Content/SliderImg/4.jpg", AudioSrc = "~/SliderAudio/4.mp3" });
return Json(listImgAudioEntity,JsonRequestBehavior.AllowGet);
}
<script>
var data;
$(function () {
var myUrl = '@Url.Action("Data", "Home")';
$.ajax({
url: myUrl,
type: "GET",
datatype: "JSON",
contentType: "application/json; charset=utf-8",
success: function rslt(msg) {
data = msg;
SetFrame(data[0].ImgSrc, data[0].AudioSrc);
}
});
});
function SetFrame(imgscr, audiosrc) {
console.log(imgscr);
console.log(audiosrc);
$('#imgSlider').attr('src', imgscr);
$('#audiosource').attr('src', audiosrc);
}
</script>
in console
Array[4]
0: Object
AudioSrc: "~/SliderAudio/1.mp3"
ImgSrc: "Content/SliderImg/1.jpg"
__proto__: Object
1: Object
2: Object
3: Object
length: 4
__proto__: Array[0]