0

I have multiple buttons to perform different actions for report of receipt. Print button does prompt user for downloading option. Code for the view is as follow:

@using (Html.BeginForm())
{ 

<fieldset style="width:525px; padding-top:20px; margin:0 auto;">
    <legend>Select Criteria</legend>

        <center>
            @Html.Partial("_MagazineType")<br /><br />
        </center>

            @Html.Partial("_RadioBtnCriteria")

            @Html.Partial("_ReportExportFormat")<br />  

        <center>                 
            <button type= "submit" id = "status" onclick="ReceiptsStatus();" >Receipts Status Details</button>
            <button type= "submit" id = "duplicate" onclick="NoDuplicate();" >No Duplicate</button>
            <button type= "submit" id = "pr_rcpt" onclick="PrintReceipts()">Print Receipts</button>                         
        </center>          

</fieldset><br />

} 

Now, when click on Receipt status detail button, it again prompts for download option as @using (Html.BeginForm()) option is used. But i just want controller action for that to run. Also depending on parameters entered it has to select among different action to be called. So how to run specific method of that button only along with parameters. Say for daterange has to pass from and to date and can pass just from date only.

dotjoe
  • 26,242
  • 5
  • 63
  • 77
Krish
  • 43
  • 1
  • 13

1 Answers1

0

THe simpliest way to have multiple buttons on the same view calling different action methods is in my opinion to surround each button with @using (HTML.BeginForm(“actionName”, “controllerName”)) and then you do not need onClick event you only need and each postback from each button will direct you to the specified actionName in specified controllerName.

this example modifies Movies tutorial from ASP.Net website:

<div style="width:100px; float:left" >
    @using (Html.BeginForm())
    {
    <p>
    <input type="submit" value="Delete" /> 
    @Html.ActionLink("Back to List", "Index")
    </p>
    }
    </div>

    <div style="width:100px; float:left">       
    @using (Html.BeginForm("Index","Movies"))
    {
    <p>
    <input type="submit" value="Cancel" /> 
    </p>
    }
</div>

hope that helps

Sirko
  • 72,589
  • 19
  • 149
  • 183