c# - Calling method from MVC view does not work -


i familiar c# / .net, pretty new .net mvc , razor things, trying is, want call method in controller view render string path binary, in view :

<img src="@url.action("readfile", "flk",  new { path = model.pict })" /> 

and in controller :

public void readfile(string path) {     response.contenttype = "image";     response.binarywrite(system.io.file.readallbytes(path)); } 

but when put debug point in controller, debug point never trigerred, clue? need advice thank you.

your readfile() method in controller should -

public actionresult readfile(string path) {     byte[] imgbytes = system.io.file.readallbytes(path);     return file(imgbytes, "image/png");  } 

here, action method reads image file byte array , uses file() method of actionresult base class send contents caller.

so can use in view -

<img src='@url.action("readfile", new { path = model.pict }))'/> 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -