asp.net mvc3 comes with jquery validate pluggin. You can customize that to show the error message in an alert instead of showing it in a page.
But think twice, do we need do this ? What if we have validations for 5 fields and user did not fill that tried to submit the form. Its gonna show 5 alerts to the user and that is not a good user experience. You can even customize the script to show the
first alert and return false there. But showing all error messages at once make the life of user easy. Thats y the validation summary messages there . How will you handle this if you use alert box ?
chenna008
Member
2 Points
46 Posts
how to show alertbox
Mar 25, 2012 01:07 PM|LINK
how to show alertbox in Razor mvc3. for validations
kshyju
Member
134 Points
39 Posts
Re: how to show alertbox
Mar 26, 2012 01:17 AM|LINK
asp.net mvc3 comes with jquery validate pluggin. You can customize that to show the error message in an alert instead of showing it in a page.
But think twice, do we need do this ? What if we have validations for 5 fields and user did not fill that tried to submit the form. Its gonna show 5 alerts to the user and that is not a good user experience. You can even customize the script to show the first alert and return false there. But showing all error messages at once make the life of user easy. Thats y the validation summary messages there . How will you handle this if you use alert box ?
My flarack profile
nirman.doshi
Participant
1520 Points
775 Posts
Re: how to show alertbox
Mar 26, 2012 05:01 PM|LINK
Agree with the above point... ValidationSummary is ideal for showing errors. rather than showing them in alert boxes.
But, yes there are certain situations where alert box can also be handy. (A scenario when a user forgets to accept License terms)
To show alert box in MVC, you should use JQuery which is by default included as you create a new MVC application.
simply, call "alert" in your client-side method in JQuery
Software Developer
Vadodara, India
thaicarrot
Contributor
5132 Points
1465 Posts
Re: how to show alertbox
Mar 27, 2012 12:47 AM|LINK
$(function($) {
var dialog = confirm('PHP is best.');
}(jQuery));
Weera
Ict-Guy
Member
106 Points
19 Posts
Re: how to show alertbox
Mar 27, 2012 01:16 AM|LINK
Have a look at this blog
ASP.NET MVC: Ajax Dialog Form Using jQuery UI
http://nickstips.wordpress.com/2011/08/11/asp-net-mvc-ajax-dialog-form-using-jquery-ui/