views:

36

answers:

1

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; byte[] fileContent = null;
    ...........
    return File(,,);
}

Why?

+1  A: 

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

Charlino
Can't believe I missed that :DI believe this has to be the right answer :)
Artiom Chilaru
Thanks a lot Charles - you were right.
Cool. Mark this answer as correct if it was right :-)
Charlino