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

[Solved] No client validation for Telerik control in MVC 3

1 Answer 115 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Gerrie
Top achievements
Rank 1
Gerrie asked on 12 Nov 2010, 11:57 PM
Hello

I have installed the MVC 3 package from Microsoft and work with the Razor view engine.
When I try to use the latest TimePicker in my project I cannot get it to validate on the client. The other properties of my model (strings) are correctly validated.

In my Layout page (masterpage) I use the following 2 script files in the head section (I'm combining Telerik with jQuery UI)

    <script src="../../Scripts/2010.3.1110/jquery-1.4.3.min.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery-ui-1.8.6.min.js" type="text/javascript"></script>

At the end of the page I use the Telerik ScriptRegistrar as follows:

    @(Html.Telerik().ScriptRegistrar()
        .jQuery(false)
        .DefaultGroup(group => group
            .Add("jquery.validate.js")
            .Add("jquery.validate.unobtrusive.js")
        )
    )

On my content page I use the following directives:

@model StockMgmt.Models.Person
@using Telerik.Web.Mvc.UI

afterwards I use a form with the following test values

    @using (Html.BeginForm())
    {
        <table>
            <tr>
                <td>@Html.LabelFor(m => m.Lastname)</td>
                <td>@Html.TextBoxFor(m => m.Lastname)</td>
                <td>@Html.ValidationMessageFor(m => m.Lastname)</td>
            </tr>
            <tr>
                <td>@Html.LabelFor(m => m.TimeModel)</td>
                <td>@Html.Telerik().TimePickerFor(m => m.TimeModel)</td>
                <td>@Html.ValidationMessageFor(x => x.TimeModel)</td>
            </tr>
        </table>

        <button type="submit">Submit Form</button>
    }

The Lastname property does give me the correct validation message, but the TimeModel property does not...

This is how my TimeModel property looks like in the Model class

        [DataType(DataType.Time)]
        [Required(ErrorMessage = "REQUIRED")]
        public DateTime? TimeModel{ get; set; }

Any help is welcome because I really want to continue to use MVC 3, razor and the Telerik extensions!

Thank you

Gerrie

1 Answer, 1 is accepted

Sort by
0
Gerrie
Top achievements
Rank 1
answered on 13 Nov 2010, 06:49 PM
Ok, I have managed to produce something that works, but I'm not sure if all the other validation mechanisms in MVC 3 will remain the same.

Set the web.config UnobtrusiveJavaScriptEnabled flag to false

  <appSettings>
    <add key="ClientValidationEnabled" value="true"/>
    <add key="UnobtrusiveJavaScriptEnabled" value="false"/>
  </appSettings>

Add the following scripts in the <head> section of the Layout.cshtml file

    <script src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.3.min.js" type="text/javascript"></script>
    <script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
    <script src="../../Scripts/MicrosoftMvcValidation.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery-ui-1.8.6.min.js" type="text/javascript"></script>

    @Html.Telerik().ScriptRegistrar().jQuery(false)

The jQuery UI is also still working which is a good sign!
People with more details and tips can always reply to this message.

Greetings

Gerrie
Tags
General Discussions
Asked by
Gerrie
Top achievements
Rank 1
Answers by
Gerrie
Top achievements
Rank 1
Share this question
or