Reputation: 2467
I am trying to submit to a controller action method by using Html.ActionLink in my view. I am doing this as non-ajax submit because the return type of my action is FileContentResult (thanks to @Darin for this info). However, my action link is not posting my view to Action Method. Below is my code
View's Code (Partial view)
@Html.ActionLink("Save", "SaveFile", "ui", new { htmlResult="asdf"})
Here, UI is controller name, SaveFile is method name.
Controller method
public FileContentResult SaveFile(string htmlString)
{
...
...
pdfBytes = pdfConverter.GetPdfBytesFromHtmlString(html);
var cd = new ContentDisposition
{
FileName = "MyFile.pdf",
Inline = false
};
Response.AddHeader("Content-Disposition", cd.ToString());
return File(pdfBytes, "application/pdf");
}
When I hit the same URL from browser address bar, then it is hit and also returns the pdf file with no issues. Same this is not happening through action link. I also tried putting the action link inside @using Html.BeginForm().... but no use.
Can you please tell me where I might be doing wrong here?
Thanks!
Upvotes: 1
Views: 2418
Reputation: 139758
Html.ActionLink
has a lots of overloads and it's very easy to use the wrong one. You are currently using the (String, String, Object, Object) overload which treats your third argument "ui"
this route values which leads to a wrongly generated link.
Use this overload instead:
@Html.ActionLink("Save", //Link text
"SaveFile", // Action Name
"ui", // Controller name
new { htmlResult="asdf"}, //Route values
null /* html attributes */)
Upvotes: 1