There might be situation where you have to use multiple button in same form. Then what would you do ?
If you don't want to mess up more in this, then let me scroll you to our main topic and show you how to do it.
Now you can see in code above I have given all 4 buttons same name as command.
<button type="submit" class="btn btn-default" name="command" id="btnMonth" value="Month" style="margin-top:25px;">Submit</button>
<button type="submit" class="btn btn-default" name="command" id="btnDay" value="Day" style="margin-top:25px;">Submit</button>
And on form submit call action as shown:
@using (Html.BeginForm("MultipleCommand", "Default", FormMethod.Post, new { id = "Form1" }))
{
}
So on button click MultipleCommand of Default controller would be called and we can use it in the as shown below.
That's it Over.
Use if else condition as if command =="blabla" {// Your code to execute } and finally return as you want.
Thanks.
If you don't want to mess up more in this, then let me scroll you to our main topic and show you how to do it.
Now you can see in code above I have given all 4 buttons same name as command.
<button type="submit" class="btn btn-default" name="command" id="btnDay" value="Day" style="margin-top:25px;">Submit</button>
And on form submit call action as shown:
@using (Html.BeginForm("MultipleCommand", "Default", FormMethod.Post, new { id = "Form1" }))
{
}
So on button click MultipleCommand of Default controller would be called and we can use it in the as shown below.
That's it Over.
Use if else condition as if command =="blabla" {// Your code to execute } and finally return as you want.
Thanks.
No comments:
Post a Comment