[Solved] Image not displaying in Image control using JQuery Ajax in ASP.Net

ishi12.shah
 
on Jan 17, 2021 10:47 PM
1655 Views

Save Binary Data in Database and display Image Using Jquery using jquery1.8.3 

    function DisplayImage(ArtNo) {
        $.ajax({
            type: "POST",
            url: currLoc + '/SetArt_NoImg',
            contentType: 'application/json; charset=utf-8',
            data: "{ 'ArtNo': '" + ArtNo + "'}",
            dataType: 'json',
            success: function (data) {
                alert(data.d);
                if (data.d != null) {
                    $("[id*=Image1]")[0].src = data.d;
                }
            },
            failure: function (response) {
                alert(response.d);
            }
        });
    }

it is return string. so it is not displayed.

    public static string SetArt_NoImg(string ArtNo)
    {
        string str = "";
        DAL dl = new DAL();
        BAL bl = new BAL();
        DataSet dsGetArtImg = new DataSet();
        bl.ArtNo = ArtNo.Trim();
        dsGetArtImg = dl.ENGG_Cut_ImgArt(bl);
 
        if (dsGetArtImg.Tables.Count > 0)
        {
            if (dsGetArtImg.Tables[0].Rows[0]["Img"].ToString() != "")
            {
                return JsonConvert.SerializeObject("data:image/jpg;base64," + Convert.ToBase64String((byte[])dsGetArtImg.Tables[0].Rows[0]["Img"]));             
            } 
        }
        return str;         
    }

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Jan 18, 2021 12:51 AM

You need to set maxJsonLength property.

Refer below article.

ASP.Net AJAX Error: The length of the string exceeds the value set on the maxJsonLength property