简体   繁体   中英

Image Loading Through Controller Issue

My Controller does not get hit and i get a 400 error when i am trying to load images through a controller as follow.

var purl = rootPath + "Fupload/EmpImg/" + $("#photofile").val();
$("#ephoto").attr("src",  purl);

However if i remove filename part (ie $("#photofile").val() ) from url then the controller gets hit.

here is my action method

public FileResult EmpImg(string id)  // id has filename
{
   .....

    String pth = ConfigurationManager.AppSettings["UploadPath"];
    pth = Path.Combine(pth, "EmpImg");

    var dir = pth;
    var path = Path.Combine(dir, id );

    if (System.IO.File.Exists(path) == false)
        return null;

    ------
    ---
}

Since the file name comes from database as json , i need to update img src through javascript as shown above. I have to pass filename to the action method and when i do it does not get hit.

How do i get this to work?

thanks.

try using url helper.. not sure what rootpath is.. but

var purl = "@Url.Action("EmpImg","Fupload")";
$("#ephoto").attr("src",  purl + '?' + $.param({id: $("#photofile").val()}));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM