Datepicker date format on server - asp.net-mvc-3

I have a probleme with date picker I have already created controllers with read/write actions and views using EF everything was OK
Till I have need to create a controller with a modelView so I chosed an empty controller and I created the views by myself
The problem is when I use datepicker with dd/MM/yy it is shown OK but when I check the value sent to the server it's null if day is >12
I tried to introduce 02/19/2008 it accepts it in the server it is sent as 19/02/2008
I didn't understand why
I try to set globalization culture and uiculture to en-US en-GB fr-FR nothing work
Is there a way to specify how date picker parse the date( I already used the datepicker.parseDate)
Need your help please

You could specify the desired format when creating the datepicker:
$('#datepicker').datepicker({ dateFormat: 'dd/mm/yyyy' })
Now you should also make sure that your server uses the same format for parsing the date either by specifying a culture or you could also write a custom model binder for the DateTime type.

I had that problem, and solution was putting globalization information in web.config.
like this: <globalization culture="sr-Latn-RS"/>
Just check that you place that in <system.web>.

Related

Max and min on date input

How do I make restrictions on my date input in Angular 2? My code currently looks like this:
<input #birthday="ngModel" type="date" name="birthday" max="2012-12-12" min="2000-12-12" required ngModel>
The following date should be invalid, but it isn't:
What am I doing wrong?
Your issue is that it is showing is valid because the only validation you have is if it's required so the input is valid. Setting the max and min date only limit the input for the date. If you try to submit you should probably see an error such as this
If the above behavior is not enough since you are seeing the input as valid, you will need a custom validator. From your code, it seems like you are using a template driven form. Adding a custom validator to a template driven form is a little more complex but you can still do it. Here is a link to a tutorial for adding a custom validator to a template driven form
https://juristr.com/blog/2016/11/ng2-template-driven-form-validators/
NOTE
Be careful with the date input type as it is not supported in a lot of browsers. You should probably look at angular calendar components such as PrimeNG calendar.

SSRS URL acces pass DDMMYY dateformat

How can I pass a date/time parameter to my report via url. I only have access to the DDMMYY format of the date. I know I should tell SSRS what language to use with the
rs:ParameterLanguage=de-DE
But I dont know what language DDMMYY is.
http://<>/ReportServer/Pages/ReportViewer.aspx?/<>/<>/report&para1=801&para2=1000011&DATE=070415&rs:ParameterLanguage=???
Oké, I guess this is not possible, but I added a hidden text parameter to the report so I could convert is with custom vbscript. and let the query decide what to use as the date parameter.

How do I properly validate DateTime in a CRUD situation for a model within an MVC project?

I have users selecting a DateTime using a caldendar/clock popup that allows them to make a selection. However, if they were to go in and edit the date to read something like: 6/12/201 10:36:47 AM instead of 6/12/2012 10:36:47 AM my Action gets past the ModelState.IsValid check and I get an error when the Controller attempts to save the object to the database (rightly so).
How do I properly validate DateTime in this situation? (I want to prevent a user from even being able to 'submit' the form if the datetime is not properly formatted)
Note: I currently have in place jquery.validate and typically (fields not DateTime) I use #Html.ValidationMessageFor(model => model.Field) - This does not appear to do anything for my current DateTime fields when they are formatted inappropriately.
you can simply add date client side validator for you DateTime field using snipet like that:
$(element).rules('add', {
date: true,
});
where "element" is your input for DateTime field.
Are you sure you're importing all of the requisite validation js files? it sounds like your server validation is working OK but the client is doing nothing. I suggest reading the following post by Brad Wilson: link

MVC 3 update entity with DateTime property

I have a MVC 3 project that uses Entity Framework. I can successfully update entities like this:
[HttpPost]
publiv RedirectResult Update(MyEntity entity)
{
if(ModelState.IsValid)
{
this.entityRepository.Update(entity);
return RedirectResult(".../Admin");
}
return RedirectResult(".../UnssuccessfullOperation");
}
Now the problem arised when I added DateTime property to my entities. If I do not add the #Html.HiddenFor for my DateTime property the date of my entity is 01.01.0001 (or DateTime.Min), which obviously cannot be saved to the database. If I add the hidden input the date is rendered but on update my ModelState is not valid and I guess this is due to the fact that the datetime is passed as a string.
Now there is one solution, but it seems a little strange - to not render Html.Hidden in the view and to use the datetime from the entityRepository like this:
entity.DateSomething = this.entityRepository.GetSingle(entity.ID).DateSomething;
but it does not seem very correct. Are there any other better options in that case?
If I add the hidden input the date is rendered but on update my
ModelState is not valid and I guess this is due to the fact that the
datetime is passed as a string.
No, I suspect that it's due to the culture setting in your application and the datetime format used in the hidden field. They probably don't match.
Take a look at the following blog post which covers the different issues that arise when parsing dates and how the format will depend on whether you are doing a GET or POST request and also a possibility to write a custom model binder to use a fixed format for dates.

Passing DateTime into TryUpdateModel

One property of my model is DateTime. I'm working with DateTime format "d.M.yyyy H:mm", i.e. day.month.year. When I pass date like 11.4.2011 (April 11th, 2011) into TryUpdateModel, it comes back as 4.11.2011, i.e. day and month swaps. Is there any way how can I instruct TryUpdateModel to parse datetime value the way I want, not the way system wants?
Thanks,
Antonin
I had the same problem and I discovered that if I use HTTPPost instead of HTTPGet MVC behaves as expected. I don't know why it solves the problem and I am still looking for the full answer to this question.

Resources