Problem with displaying image from DB using asp.net MVC 2

后端 未结 5 1845
情话喂你
情话喂你 2021-01-17 00:41

I\'m having trouble with displaying image from db. I think that method for saving image is working, because I see in DB that varbinary fields have some value, and that image

5条回答
  •  轮回少年
    2021-01-17 00:57

    My guess is that you have a routing issue. If the url /product/getimage/18 should work for your action you need to have a route that looks something like this:

    routes.MapRoute("ProductImage",
        "product/getimage/{productID}",
        new { controller = "Product", action = "GetImage", productID = "" }
    );
    

    To confirm this you should use firebug and check the "net" tab (or set a breakpoint in your action and see if it gets hit when you load the page).

    I would also recommend using the build in helpers to generate your urls (then this kind of problem will never happen). Instead of src='/product/getimage/<%= Html.Encode(product.ID) %>' you can write src='<%=Url.Action("GetImage", "Product", new { productID = product.ID })%>'

提交回复
热议问题