This is a migrated thread and some comments may be shown as answers.

[Solved] Displaying Validation Messages in MVC 3 Window Control

5 Answers 229 Views
Window
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Darren
Top achievements
Rank 1
Darren asked on 18 May 2011, 07:57 PM
I have an ASP.NET MVC data entry form.  I am using data annotations on the model to specify the validations to be performed.  However, I would like to display the Validation Summary in a modal Telerik Window control.  

I currently have the following defined for the window:

@{Html.Telerik().Window()
      .Name("ErrorMsgWindow")
      .Draggable(true)
      .Buttons(b =>
      {
          b.Close();
      })
      .Modal(false)
      .Resizable(r =>
      {
          r.Enabled(true);
          r.MinHeight(350);
          r.MinWidth(560);
      })
      .Scrollable(true)
      .Visible(true)
      .Content(
        @<text>
            @Html.ValidationSummary()
        </text>
       )
      .Render(); 
}

I have two separate issues that I haven't been able to resolve:

1)  You may notice from the code sample above that the Window is currently visible (for testing).  When I click on the Submit button for the form, the validation messages are displayed next to their corresponding controls, but nothing is displayed in the window.  I am suspicious that this is due to the Validation Summary in the Window not being contained in the same form.  But, I'm not sure how to get at the data to populate it manually.

2)  I would like to make the window invisible and only display it when there are errors.  However, I haven't been able to find the correct event to capture the result of the client-side validation and show the Window appropriately.

Any ideas, samples, blog posts, etc. describing how to accomplish this would be greatly appreciated.

Regards,

-Darren

5 Answers, 1 is accepted

Sort by
0
nachid
Top achievements
Rank 1
answered on 18 May 2011, 11:46 PM
There are two options

1) Display the window before the form is submitted to the server
In this case, you can check if the form is valid with $(form).valid()
if ( $(form).valid() )
{
 display your window
}

2) Display the window after the window is submitted to the server
Html.ValidationSummary is filled and you can check for .this class validation-summary-errors
 if (form).hasClass('validation-summary-errors'))
{
 display your window
}
0
Darren
Top achievements
Rank 1
answered on 19 May 2011, 01:14 AM
Hey, Nachid.

Thanks for the reply. 

So, what event should I tie into?  I have tried the OnFailure event of the AJAX form, but it appears that it isn't fired unless the AJAX call to the controller returns an error.  But, the validation is being done client-side, so the form will never be posted, unless the validation passes. 

I guess what I am looking for is an event that will fire after the client-side validation and before posting the data.  Any ideas?

Thanks,

-Darren
0
Accepted
nachid
Top achievements
Rank 1
answered on 19 May 2011, 08:47 AM
Hook some code in the submit button event
Have a visit to Validate function. It has so many options
0
Darren
Top achievements
Rank 1
answered on 23 May 2011, 05:42 PM
I will play around with this.  Thank you very much!
0
Christian
Top achievements
Rank 1
answered on 05 Jul 2012, 03:52 PM

Darren, did you find a resolution to your problem?  I am trying to do the same thing and would love to see how you solved it.

Thanks!

Christian
Tags
Window
Asked by
Darren
Top achievements
Rank 1
Answers by
nachid
Top achievements
Rank 1
Darren
Top achievements
Rank 1
Christian
Top achievements
Rank 1
Share this question
or