I am calling an image for when a particular condition is met, i want to call this image through a webservice then use a function in jquery to call the method. But i am unable to gain access to a variable defined within the method to successfully draw this image.
This is the code in my webservice
[WebMethod]
public void DisplayStar()
{
List<The_Factory_Chante.Models.Star> stars;
using (The_Factory_Chante.Models.The_FactoryDBContext db2 = new The_Factory_Chante.Models.The_FactoryDBContext())
{
string imageSource = "";
stars = db2.Stars.ToList();
foreach (var item in stars)
{
if (item.starImage != null)
{
string imageBase = Convert.ToBase64String(item.starImage);
imageSource = string.Format("data:image/gif;base64,{0}", imageBase);
}
}
}
}
This is the code found in my .cshtml class to call the method in jquery
function DisplayStar() {
$.ajax({
url: "../../http://ift.tt/1JBoTtL",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (data) {
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
}
});
};
The problem is i want to use this piece of code to be able to successfully draw this image but i am unable to gain access to the "imageSource" variable in my method.
<img src="@imageSource" class="star"/>
Can anyone help me with this or possibly shed light in any other way to achieve this. Thank you.
Aucun commentaire:
Enregistrer un commentaire