I am currently using ajax jquery to populate an img src with a dynamic value. Since the image is going to the server anyway i would like to cut out the jquery portion of the code
What I currently have
Javascript (this is the code i want to trash)
var Onload= function () {
$.each($('.image'), function (x, item) {
$.ajax({
url: '/MyController/MyAction/?imageName=' + $(item).attr('data-image-name'),
type: 'GET',
dataType: 'html',
success: function (data) {
$(item).attr('src', data);
},
error: function (jqXHR, textStatus, errorThrown) {
}
});
});
};
Server side code
public string MyAction(string imageName)
{
return imageUrl = _myService.GetImageUrl(imageName);
}
HTML
@foreach(var i in Model)
{
<img src="" class="image" data-image-name="@i.Name"/>//this is current html
//<img src="/MyController/Myaction/imageName" + @i.Name />
//i am trying to get something like second img tag
//but if i do this it populates with the controller/action url,
//not the result of the action method url
}
I know about viewmodels and things of that sort. I am not looking for an answer that says, "put this info into your model/viewmodel."