Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7839021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:17:34+00:00 2026-06-02T15:17:34+00:00

I have this controller method in my FilesController: public ActionResult Download(int id, string filename)

  • 0

I have this controller method in my FilesController:

public ActionResult Download(int id, string filename)
{
    var file = _filesRepository.GetFile(id);

    // Write it back to the client
    Response.ContentType = file.FileMimeType;
    Response.AddHeader("content-disposition", "attachment; filename=" + file.FileName);
    Response.BinaryWrite(file.FileData);

    return new EmptyResult();
}

This works if I navigate to

/Files/Download/123?filename=myimage.png

But I’d like it work if I navigate to

/Files/Download/123/myimage.png

I know I need to create a custom route for this, but everything I’ve tried isn’t working. I’d like it to accept two parameters for only the FilesController and Download method. Is that possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T15:17:36+00:00Added an answer on June 2, 2026 at 3:17 pm

    Yes, this is very easy if you create a new route. In your Global.asax.cs file, before the default route, add the following route:

    routes.MapRoute(
      "FileDownload", // Route name
      "Files/Download/{id}/{filename}", // URL with parameters
      new { 
        controller = "Files", 
        action = "Download", 
        id = UrlParameter.Optional, 
        filename = UrlParameter.Optional 
      } // Parameter defaults
    );
    

    Then your controller action should work as you currently have it defined.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this controller method: public JsonResult List(int number) { var list = new
I have this controller method: public ActionResult Index(string searchError) { // get all errors
I have a controller method: public ActionResult Details(int id) { Order order = OrderFacade.Instance.Load(id);
i have this controller: public ActionResult Novo() { var products = context.Product.Select(x => new
I have this constructor; public UmlDiagramEntity(ReportElement reportElement, int pageIndex, Controller controller) { super(reportElement.getX1(), reportElement.getY1(),
I have a controller method that looks like public ViewResult Index(string id, string participant=,
I have a controller method that is a little something like this: def suggestions
I have 2 functions/methods in the same controller in CodeIgniter like this: public function
I am getting some unexpected behavior from Html.EditorFor(). I have this controller: [HandleError] public
I have this Controller : @Controller @RequestMapping(/path/*) public class MyController { @RequestMapping(value = /,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.