开发者

Showing an image after loading it from sql database

I have a problem showing the image form database in a view Details and a ImageController. Inside the view I have:

img src=Url.Action("GetFile","Image", new {id= Model.id})

and in controller:

public FileContentResult GetFile(int idl)
{
    //int idl = 32;
    SqlDataReader rdr; byte[] fileContent = null;
    ...........
    return File(,,);
}

When the view is called, function GetFile it just won't work. But if I cut out the parameter int id1 and I instantiate it as a variable it does work.

public FileContentResult GetFile()
{
    int idl = 32;
    SqlDataReader rdr开发者_C百科; byte[] fileContent = null;
    ...........
    return File(,,);
}

Why?


I think your id value isn't getting bound because your action parameter is idl and the databinder doesn't have a route value to bind to the idl parameter.

You see, your action parameters should match route values. I'm guessing that you are simply using the default route of {controller}/{action}/{id} - if this is the case then you need to change your GetFile action to have a parameter of id and not idl. Otherwise you need to create your own route that looks something like `Image/GetFile/{idl}.

Savvy?

HTHs,
Charles

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜