1

I have a Action in controller as

public ActionResult Download()    
{ 
    return File(FileStream, "application/octet-stream", fileName); 
}

If I want to use FilePathresult as:

public FilePathResult Download()
{ 
    return File(FileStream, "application/octet-stream", fileName);
}

can I call the Download() on click of a button like this

@Html.ActionLink("FileDownload", "Download", new { file = item.FileName, GuID = item.DocumentGuID }) /text).Width(10); 

Also is the implementation of Download() is correct in the second instance i.e.,in

public FilePathResult Download()

?

1
  • Why do not you try and see for yourself? If you already didi, what is the problem? Commented Jun 9, 2012 at 16:49

1 Answer 1

2

Your ActionLink defines parameters that you want to pass so you will need to add those to your action

@Html.ActionLink("FileDownload", "Download", new { file = item.FileName, GuID = item.DocumentGuID }) /text).Width(10); 

I'm not sure what /text.Width(10); is doing there but a properly formed ActionLink with parameters also must define the Html Attributes as the last parameter, just pass in null.

Here is an example of a properly formed ActionLink.

@Html.ActionLink("ActionName", "ControllerName", new { id = 10}, null)

You have a file and a GuID parameter in your link, so add those to your action as parameters.

public FilePathResult Download(string file, Guid GuID)
{ 
    return File(FileStream, "application/octet-stream", fileName);
}

Give it a try and let us know what happens :-)

Happy coding!

Sign up to request clarification or add additional context in comments.

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.