Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
DataType.Date
Message
 
 
À
30/08/2012 21:38:22
Information générale
Forum:
ASP.NET
Catégorie:
MVC
Titre:
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01551951
Message ID:
01552105
Vues:
48
>Here's a simple example
>
>@model Dates.Models.Person
>
><script src="~/Scripts/jquery-1.7.1.js"></script>
><script src="~/Scripts/jquery-ui-1.8.20.js"></script>
>
><script type="text/javascript">
>    $(document).ready(function() {
>    $('.datepicker').datepicker();
>    });
></script>
>
>@using (Html.BeginForm()) {
>    @Html.ValidationSummary(true)
>
>    <div class="editor-label">
>        @Html.LabelFor(model => model.Birthdate)
>    </div>
>    <div class="editor-field">
>        @Html.TextBoxFor(model => model.Birthdate, "", new {@class = "datepicker"})
>        @Html.ValidationMessageFor(model => model.Birthdate)
>    </div>
>    <input type="submit" value="Create" />
>}
>
>
>This will cause any item with the class .datepicker to fire the datepicker when you enter the field. Optionally, you can have it based on the id of the field. MVC uses the fieldname as the id, so in the jquery code, change .datepicker to #Birthdate.
>
>Also note that the default EditorFor has been changed to TextBoxFor.
>
>>I tried using exact code from Rob and naming the template Date, but the calendar doesn't pop up. However, I think the template was picked up as I originally used it as is (with space before script) and I saw that whole text rendered.
>>
>>Can you please help me to figure out how to fix what Rob used?
>>
>>Thanks again.

This is the example we used in the course and it indeed worked (don't know if it will still work after all my today's changes).

However, my goal is to not write TextBoxFor and remember to add class datepicker and have the script in the view. I want to be able to set Data Annotations in the model to be [DataType(DataType.Date)] and let the EditorFor figure out that it needs to show date picker.

The blog and idea from Rob partially works, so now I want to be able to contact Brad Wilson to discuss why it does not work. I tried to send him a twitter message, but I don't use twitter a lot, so I don't know if it reached him or not.

I also posted this message http://forums.asp.net/t/1839133.aspx/1?Nullable+date+types+are+returned+as+null+back+to+the+browser
where I provided more info about my troubles.

Right now, the approach in that tutorial doesn't exactly work. In IE9 I don't see picker at all, in FireFox it's a picker, in Chrome it's HTML5 picker.
In IE9 and Chrome (haven't tested in FireFox) I am no longer able to Create or Edit, I got an exception from ValidateModel. The dates are being passed back as nulls.

So, what exactly is wrong?

Thanks.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform