Skip to content

Cheap Windows Hosting ASP.NET

ASP.NET Hosting Cheap | Faster

X
  • Hosting Award
  • Hosting Comparison
  • Hosting Review
  • Tutorial
  • Contact
Menu

ASP.NET MVC 6 Tutorial :: Handle Multiple Submit Buttons On The Same Form in MVC 6

Posted on June 23, 2016 by Mary Bacine

In this post I will explain you about Handling multiple submit buttons on the same form in MVC.To fix this problem, I’m progressing to justify the varied techniques for handling multiple buttons on the same form in MVC.

img (1)

Sometimes you got situation like more than one submit buttons on a similar form in ASP.NET MVC 6. At that point, How we will handle the click event of every and each buttons on your form? Suppose you’ve got a user Login form like as below:

Screenshot_1

On the above picture, we have the SignUp, SignIn and the Cancel buttons. Suppose on Signup button click you have to open Signup window & on SignIn button click you have to open Login window and on Cancel button click you are returning to home page. For handling all of the above buttons, we have the following methods:

Export Gridview to Excel: Gridview to Excel
Insert,Update,Delete in ModalPopup CRUD operation in ModalPopup
Read and Write in Text File in ASP.NET Read and Write File in ASP.NET

Now, Make the view Form with Multiple Button in Home Folder with the following code.

MultipleCommand.cshtml
@model Mvc4_Multiple_Submit_Button.Models.RegistrationModel
@{
ViewBag.Title = "Handling Multiple Command Buttons";
}
<script src="../../Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.validate.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.validate.unobtrusive.min.js" type="text/javascript"></script>
<h2>User's Signup Form</h2>
@using (Html.BeginForm("MultipleCommand", "Home", FormMethod.Post, new { id = "submitForm" }))
{
<fieldset>
<legend>Registration Form</legend>
<ol>
<li>
@Html.LabelFor(m => m.Name)
@Html.TextBoxFor(m => m.Name, new { maxlength = 50 })
@Html.ValidationMessageFor(m => m.Name)
</li>
<li>
@Html.LabelFor(m => m.Address)
@Html.TextAreaFor(m => m.Address, new { maxlength = 200 })
@Html.ValidationMessageFor(m => m.Address)
</li>
<li>
@Html.LabelFor(m => m.MobileNo)
@Html.TextBoxFor(m => m.MobileNo, new { maxlength = 10 })
@Html.ValidationMessageFor(m => m.MobileNo)
</li>
</ol>
<button type="submit" id="btnSave" name="Command" value="Save">
Save</button>
<button type="submit" id="btnSubmit" name="Command" value="Submit">
Submit</button>
<button type="submit" id="btnCancel" name="Command" value="Cancel" onclick="$('#submitForm').submit()">
Cancel (Server Side)</button>
<button type="submit" id="btnCancelSecForm" name="Command" value="Cancel" onclick="$('#cancelForm').submit()">
Cancel (Server Side by Second Form)</button>
<button name="ClientCancel" type="button" onclick=" document.location.href = $('#cancelUrl').attr('href');">
Cancel (Client Side)</button>
<a id="cancelUrl" href="@Html.AttributeEncode(Url.Action("Index", "Home"))" style="display:none;">
</a>
</fieldset>
}
@using (Html.BeginForm("MultipleButtonCancel", "Home", FormMethod.Post, new { id = "cancelForm" })) { }

Next step, in Homecontroller include the MultipleCommand Method to handle the multiple button with the following code.

HomeController.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Mvc4_Multiple_Submit_Button.Models;
namespace Mvc4_Multiple_Submit_Button.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult MultipleCommand()
{
return View();
}
[HttpPost]
public ActionResult MultipleCommand(RegistrationModel mReg, string Command)
{
if (Command == "Save")
{
//TO DO : for Save button Click
}
else if (Command == "Submit")
{
//TO DO : for Submit button Click
}
else
{
//TO DO : for Cancel button Click
return RedirectToAction("Index");
}
return View();
}
[HttpPost]
public ActionResult MultipleButtonCancel()
{
//TO DO : for Cancel button Click
return RedirectToAction("Index");
}
}
}
HostForLIFE.eu
HostForLIFE.eu revolutionized hosting with Plesk Control Panel, a Web-based interface that provides customers with 24×7 access to their server and site configuration tools. Plesk completes requests in seconds. It is included free with each hosting account. Renowned for its comprehensive functionality – beyond other hosting control panels – and ease of use, Plesk Control Panel is available only to HostForLIFE’s customers. They offer a highly redundant, carrier-class architecture, designed around the needs of shared hosting customers.
Posted in ASP.NET MVC, Hosting TutorialTagged ASP.NET MVC 6, asp.net mvc 6 tutorial, ASP.NET MVC Tutorial, Handle Multiple Submit Buttons On The Same Form in MVC 6

Post navigation

Best and Cheap IIS 8.5 Hosting Provider
Best and Cheap ASP.NET MVC 5 Hosting Service

Related Post

  • Best Cheap ASP.NET MVC 6 Hosting in Europe
  • Benefits of Social Marketing
  • Cheap and Best Windows ASP.NET Hosting :: HostForLIFE.eu VS VidaHost
  • Best and Cheap ASP.NET MVC 5 Hosting Service
  • Best and Cheap IIS 8.5 Hosting Provider
  • ASP.NET Tutorial :: Remove XML Formatter from ASP.NET Web API Applications
  • ASP.NET MVC 6 Tutorial :: Migrate ASP.NET Web API 2 To MVC 6
  • ASP.NET 4.5 Tutorial – Timeout in ASP.NET 4.5 With Regex
  • SQL Server 2016 Tutorial :: Create a JSON Document Using SQL Server 2016

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Best SQL 2016 Hosting

Categories

  • ASP.NET
  • ASP.NET Ajax
  • ASP.NET MVC
  • Entity Framework
  • Hosting Comparison
  • Hosting Review
  • Hosting Tutorial
  • IIS
  • Joomla
  • nopCommerce
  • Silverlight
  • SQL Server

Recent Posts

  • A2 Hosting vs ASPHostPortal ASP.NET Hosting – Who is Your Favourite?
  • Looking for A2 ASP.NET Hosting Alternatives?
  • Windows Dedicated Server with HostForLIFE.eu. Is it Good?
  • Let’s Move From Ionos ASP.NET Hosting
  • Choosing Your Best ASP.NET Core Hosting Provider: ASPHostPortal.com VS GoDaddy in Comparison

Our Partner

  • Best ASP.NET Hosting
  • Best Windows Hosting
  • Cloud ASP.NET Hosting
  • ECommerce Hosting Review
  • Recommended ASP.NET
  • Reliable Windows Hosting
  • Review ASP.NET Hosting
  • Windows Hosting Bulletin
  • Windows Hosting Leaders
  • Windows ASP.NET Hosting
  • Windows Hosting Review
  • Best Cheap Hosting ASP.NET
  • Hosting Review ASP.NET
  • Full Trust Hosting ASP.NET
  • Cheap Australia ASP.NET Hosting
  • Review Core ASP Hosting
  • Cheap Australia ASP.NET Hosting
  • Best Cloud ASP.NET Hosting
  • Creative Videos
  • Business Vendor
  • Reliable ASP.NET Hosting
  • Cheap ASP.NET Hosting Review
  • European ASP.NET Hosting
  • UK ASP.NET Hosting
  • ASP.NET Hosting Review
  • India ASP.NET Hosting
  • Best India ASP.NET Hosting
  • Cheap ASP.NET Hosting Review
  • Best ASP.NET Hosting Review
  • Easy Hosting ASP.NET
  • Cheap Windows Hosting
  • Reliable ASP.NET Hosting Review
Created by cheapwindowshostingasp.net
  • Hosting Award
  • Hosting Comparison
  • Hosting Review
  • Tutorial
  • Contact