开发者

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

开发者 https://www.devze.com 2023-03-27 23:27 出处:网络
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

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

精彩评论

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

关注公众号