Multiple submit buttons in a MVC4 view using custom attribute

This post is targeted to anyone who is a beginner in MVC and finds oneself fidgeting over difficulties encountered during its learning curve.  While MVC is a very interesting architecture to work with, I personally felt it really tests one’s patience until you get a hang of it.

One of the common issues that most people face as a MVC novice developer is implementing multiple submit buttons in a form in MVC view. Recently, I had a similar scenario and thought it would a good idea to put it into an article for future reference.

The following three steps elaborate the solution to this problem.

1. We need to create a custom attribute that would match the action name with the name attribute of the button.

3

Continue reading

Advertisements

Implementing masked input in MVC4

In any application, whether it be web or desktop application, the user needs to conform to a set format or template while entering the data into a form. This is solely done for the purpose of data integrity. This is where the concept of “masked input” comes in. As per Wikipedia, “an input mask refers to a string expression, defined by a developer, that governs what a user is allowed to enter in as input in a text box.” Some of the frequently used input for masking include Date, Time, Phone, SSN, Product Key , Zip codes, Postal codes and so forth as shown here.

One method of easily implementing masked input is by using jquery. However, it has a serious drawback that we have to link jquery function for each input that we need to mask. There are a couple of good plugins available for this but all pose the same issue.

Another workaround is to create a data annotation for masking input and using it in our views or viewModels. The intent of this post is to walk-through this alternative approach.

Continue reading