开发者

create a link to open a pdf in the navigateur with asp.net mvc2

I work a project with asp.net mvc2 (c sharp ).I want to create a link to open a pdf in the navigateur, t开发者_如何学编程he path of the pdf exixte in my data base .


You could design a controller action which will fetch the pdf path from the database and stream it to the response:

public ActionResult ShowPdf()
{
    string path = ... fetch path from database
    if (!System.IO.File.Exists(path))
    {
        // the file was not found
        throw new HttpException(404, "Not found");
    }
    return File(path, "application/pdf", "test.pdf");
}

and then you could create a link to this action in your view:

<%= Html.ActionLink("download pdf", "showpdf", "somecontroller") %>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜