ASP.Net MVC & Multiple Submit Button

ASP.Net MVC & Multiple Submit Button

While developing any web applications we use to design lot more forms. Most of the times a form perform a single action, posting data to some controller. There is no necessity that each of the form will contain only a single submit button. Sometimes, we may need a form which will contain multiple submit buttons.  As in the following case

So in this case, our form will be posting data to a single action Post but it contains 2 different submit button.  So to handle this scenario, we need to code something like this in our controller.

Also this looks very simple when we have a simple Action, think how about doing this on a form of 10 fields & 4 buttons.

How if I am able to specify the name of the button near the action method wherein I will specify the name of the button on which that action needs to be invoked.  We can achieve this in Asp.Net MVC by using the ActionMethodSelectorAttribute attribute. Here is a code snippet to show the use of the attribute

The ActionMethodSelectorAttribute is executed before the Action is executed, so we here we can check which button is clicked while submitting the form using the Form NameValueCollection object on the IsValidForRequest event of the ActionMethodSelectorAttribute.

Here is the implementation code for the class.

This attribute will also help preventing the JavaScript attacks as this will only accept the values submitted by the specific submit button.

You can download the source code here.

Getting Started With ASP.Net MVC 4

This is my first post about ASP.Net MVC 4. I will be providing some links for ASP.Net MVC 4 which includes information about downloading & installing ASP.Net MVC 4.
ASP.NET MVC 4 NuGet Packages
One good news is that MVC 4 is also available via NuGet. To install MVC 4 via NuGet, type following in the Package Manager Console.

For more detail regarding NuGet package please visit http://www.nuget.org/List/Packages/AspNetMvc

ASP.NET MVC 4 for Visual Studio 2010
If you are using Visual Studio 2010 then you can use MVC 4 with Visual Studio 2010. To install MVC 4 via Web Platform Installer for Visual Studio 2010 please visit following link.
http://www.microsoft.com/web/gallery/install.aspx?appid=MVC4VS2010&prerelease=true

ASP.NET MVC 4 for Visual Studio 11 Developer Preview
If you are using Visual Studio 11 Developer Preview then you can install MVC 4 in Visual Studio 11 Developer Preview via following link.
http://www.microsoft.com/web/gallery/install.aspx?appid=MVC4VS11&prerelease=true

ASP.NET MVC 4 Direct Download Link
For Visual Studio 2010, first you need to install Visual Studio 2010 SP1 KB983509 viahttp://download.microsoft.com/download/2/3/0/230C4F4A-2D3C-4D3B-B991-2A9133904E35/VS10sp1-KB983509.exe

MVC 4 Direct link for Visual Studio 2010 http://download.microsoft.com/download/E/D/7/ED7CB028-2CBD-4E26-87D5-C9164A0B4849/AspNetMVC4VisualStudio2010Setup.exe

MVC 4 Direct link for Visual Studio 11 Developer Previewhttp://download.microsoft.com/download/E/D/7/ED7CB028-2CBD-4E26-87D5-C9164A0B4849/AspNetMVC4VisualStudio11Setup.exe

Here are some useful links about MVC4