I am trying to make a button in html that when it is clicked, it calls a method that is in my controller that will create a pdf.
my controller is DashboardController, my method is called PrintConfirm()
here is my html:
<a onclick="<%:Url.Action("PrintConfirm")/%>fileName" rel="external" target="_blank">
<button class="ui-icon ui-icon-print" data-role ="button">Print Confirmation</button>
</a>
When I run it, all I get is a printer icon and nothing happens when I click on it
Your gator tag is incorrect, and your
onclickshould behref. Try this:In addition, you cannot call a void method from the view. Only actions may be invoked, and actions must have a return type of
ActionResult.Also, if your
PrintConfirmaction is on different controller than the one which returned the current view, you’ll need to specify that controller’s name as well.Edit
If you were just trying to invoke the action asynchronously, you’ll probably want to use jQuery and AJAX. Let me know if you’d like an example.