1

I have a pdf file which I would like to a create a route map for it. Is there a way to make object default take a url in stead of action controller combination?

Instead of

 routes.MapRoute("MyRouteName", "MyNiceUrl", new { controller = "ControllerName", action = "ActionName" });

Have something like

 routes.MapRoute("MyRouteName", "MyNiceUrl", new { relativeUrl="MyrelativeUrl" });

2 Answers 2

2

You don't need routes for static resources. You need url helpers to reference them:

<a href="<%= Url.Content("~/Content/test.pdf") %>">Download pdf</a>

And if you wanted to have an url like /SomeController/MyNiceUrl to serve your pdf file you could simply write a controller action:

public ActionResult MyNiceUrl()
{
    var pdf = Server.MapPath("~/Content/test.pdf");
    return File(pdf, "application/pdf");
}

and then:

<%= Html.ActionLink("Download pdf", "MyNiceUrl", "SomeController") %>
Sign up to request clarification or add additional context in comments.

Comments

0

As in this answer:

Use your controller, or create a mini-controller, and then use the Redirect ActionResult:

public class MyController : Controller
{
    public ActionResult Pdf()
    {
        return Redirect( Url.Content( "mydoc.pdf" ) );
    }

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.