showing error message from a custom validator or MVC3 - asp.net-mvc-3

i'm using this solution An ASP.NET MVC validator to make sure at least one checkbox is checked to have at least one checkbox checked on my form. But i can't figure out how to display the error message, in unobstrusive.
I suppose i should use a ValidationMessageFor with a custom script for the client side.

Related

Kendo UI Client Side Validation erros as list

I am using Kendo UI ASP.Net MVC framework and I have a kendo grid one of our pages. I am able do client side validation when the grid is in edit mode(using in-line editing). Any error messages are displayed next to the field, it is possible to get all these errors and display them as a list when the Update button is clicked on the row.
No, such validation summary is not supported, however you can customize where the messages are shown like explained here.

Validating form using jquery Ajax MVC

Up to this point, I’ve been using Microsoft Ajax for updates in my MVC app. I’m now switching to jQuery Ajax in order to standardize my approach.
However, I just realized that the required field in my model for the form did not fire and the user was able to submit the form even though some required fields were left blank.
What is the standard way to handle required fields if I’m handling my ajax functions using jQuery – i.e. I want the unobtrusive to handle my required fields by highlighting them and not allow the submit button to be clicked.
Also, to mention I am getting data-val attributes through the model.
P.S. I’m now using an event handler to detect click event on submit button for the form. In other words, I’m not using #using.Ajax.BeginForm to define my form.

MVC 3 unobtrusive jquery validate - how to add a Dummy message to Vallidation Summary

I get some error messages from the back end service and I want them to be displayed in the Validation Summary control on the page.
I am using MVC 3 and ValidationSummary is not on the page till a validation fails due to unobtrusive stuff i believe.
I looked at the following example but it does not work with MVC 3.
Does anyone knows how to simply insert an error message in Validation summary control in MVC 3 with all the unobtrusive stuff switched on?
Thanks,
Dexter
It sounds like this article on Remote Validation should do the trick.
Of course, you will still need to make sure you print the ValidationSummary in your views:
<%= Html.ValidationSummary("There are errors that must be fixed:")%>

MVC 3 Client Side Validation Catches Some ValidationAttributes but not others?

I'm confused by this behavior:
I have an out-of-the-box MVC3 app. I haven't really done any customization from the what the scaffolding template gives me.
In web.config, clientsidevalidationenabled and unobtrusivevalidation are both true.
I have a class with one field using the Required annotation, one using StringLength and one using RegularExpression. When I'm editing an object, the textboxes for the properties marked with StringLength & Regex report problems instantly in the UI, but the textbox for the Required doesn't.
If I hit SAVE, then "Model.IsValid" is the controller sess the problem with the missing Required and I get the UI error message next to the text box.
If I view the source of the page, I can see that the markup for the required property does have the dataval-req and other related attributes generated by the Unobtrusive validation.
Is this expected behavior? If it is, what's the reason? If it's not, what might I be doing wrong?
Thanks! :)
As long as the page is not posting back to the server, this should be the correct behavior. The required client-validation will fire only if:
You don't enter data and try to post to the server.
You enter data in the text box and then remove it.
Otherwise the user would be inundated with error messages.
I've gotten to the bottom of this behavior, just by banging on the keyboard some more. It's as expected. In the Create view, the behavior is as #Beavis describes. In the edit view, unobtrusive validation prevents the required property from being validated on tabbing BEFORE the first attempt at hitting SAVE. SAVE then does a UI validation (no postback occurs) and shows the error message next to the property. Once I've hit save that first time, that property responds to tabbing. So now if I make it valid, the message disappears on tab. If I erase the contents of the text box, the message reappears on tab.
Thanks for everyone's help.

MVC2 Validation

My application uses MVC validation explained here:
http://blog.stevensanderson.com/2010/01/28/validating-a-variable-length-list-aspnet-mvc-2-style/
And it works fine with both server and client validation when the form is posted. However my problem is that I would like to have client validation on one of the fields before the form is posted. So when the TextBox loses focus it is validated directly.
I have solved it by using jQuery validation on the field that is validated before the form is posted.
You must use JQuery validations so that it will validate before posting. It also highlights those area where validation fails.

Resources