You can not display only year with model parameters because the DataFormatString ="{0:yyyy}" is not allowed in mvc. You can display either month and year or date-month-year
Blockchain software companies india
http://www.ifourtechnolab.com/blockchain-technology
public class MyModel
{
[Display(Name = "Some Date")]
public DateTime somedate { get; set; }
}
Result:
Best Regards,
Jerry Cai
ASP.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today. Learn more >
You can not display only year with model parameters because the DataFormatString ="{0:yyyy}" is not allowed in mvc. You can display either month and year or date-month-year
Thank you for that. It seemed like it was fixed because nothing changed it
Yes, thats the solution in place now, thank you! I know that solution works. Was hoping to say in the model the type is of Date so the assumption was it would accept any date type but thats not the case. Its boxed into YYYY-mm-dd. So in the field that
wants the year only the type is string, when i changed the model it got errors in the DOM looking at F12 showing how values are not formatted properly as yyyy-mm-dd so javascript halts.
Is there a better platform to use? Currently long regular expressions in the Model to check for date or similar content and built in MVC is not robust enough
The bigger problem is one I had before,
public string StartingDate
public string Incident1Startdate
public string Incident2Startdate
public string Incident3Startdate
public string Incident1Closedate
public string Incident2Closedate
public string Incident3Closedate
Then the bounds checking so that no incident date can be BEFORE the start date, no incidentN close date can be earlier than the incidentN start date, common sense checking. How can it be coded up to say
if(Incident1Startdate < StartingDate)
{
Incident1Startdate = invalid;
Incident1Startdate.ErrorMessage.Show();
}
and then the same for all dates and the usual parameters that have to be within the bounds. Wonder if one of these other platforms like Angular or React or? take this into consideration and include as part of their framework for building a UI? So something
like:
Make StartingDate < Incident1Startdate, Incident2Startdate, Incident3Startdate, (ErrorMessage="check the date");
Make Incident1Startdate < Incident1Stopdate;
Or each date field has to be manually coded. Which is fine, just didnt want to overlook some function that did this already
Sorry for the delay, to your first question ,I can use my demo well even I changed the type to 'string', can you offer your code so I can reproduce it?
And to your second question, I noticed that you have opened a new thread about it so I answerd you in that thread, hope it can help.
Best Regards,
Jerry Cai.
ASP.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today. Learn more >
Member
126 Points
878 Posts
How to do Client side validation using model parameters?
Oct 09, 2020 01:26 AM|rogersbr|LINK
Have an MVC c# asp.net 4.5 app and switiching from using jquery for validation, back to built in validation in the Model
Problem: Date values. Maybe havent found the parameters to change but for some I need the value to be Year only
[DisplayFormat(DataFormatString = "{0:yyyy}", ApplyFormatInEditMode = true)]
Textbox? has mm/dd/yyyy and an icon I DONT WANT that represents click to open the Calendar. The Calendar should only show years, like 2000 to 2050.
But what is there? Normal calendar, click a date and its 10/13/2020
How can it be coerced into only showing the Year?
Its an EditFor
Tried putting the format string in
to the View html, didnt change anything
[Display(Name="Some Date")]
[DataType(DataType.Date)]
public string somedate {get; set;}
Shows mm/dd/yyyy in the EditFor and normal datepicker with days and months... just want years
Member
70 Points
80 Posts
Re: How to do Client side validation using model parameters?
Oct 09, 2020 05:13 AM|ifour.parth@gmail.com|LINK
You can not display only year with model parameters because the DataFormatString ="{0:yyyy}" is not allowed in mvc. You can display either month and year or date-month-year
http://www.ifourtechnolab.com/blockchain-technology
Participant
1120 Points
372 Posts
Re: How to do Client side validation using model parameters?
Oct 09, 2020 06:24 AM|Jerry Cai|LINK
Hi,rogersbr
First I recommend you use Datetime as the type of the somedate.
1,If you want to read the date in your model from Controller, you should just delete [DataType(DataType.Date)].
2,If you want to choose the Date that has only year in calendar, you should add a js,The following is my demo:
Model:
Result:
Best Regards,
Jerry Cai
Member
126 Points
878 Posts
Re: How to do Client side validation using model parameters?
Oct 09, 2020 02:55 PM|rogersbr|LINK
Thank you for that. It seemed like it was fixed because nothing changed it
Member
126 Points
878 Posts
Re: How to do Client side validation using model parameters?
Oct 09, 2020 03:26 PM|rogersbr|LINK
Hi Jerry,
Yes, thats the solution in place now, thank you! I know that solution works. Was hoping to say in the model the type is of Date so the assumption was it would accept any date type but thats not the case. Its boxed into YYYY-mm-dd. So in the field that wants the year only the type is string, when i changed the model it got errors in the DOM looking at F12 showing how values are not formatted properly as yyyy-mm-dd so javascript halts.
Is there a better platform to use? Currently long regular expressions in the Model to check for date or similar content and built in MVC is not robust enough
The bigger problem is one I had before,
public string StartingDate
public string Incident1Startdate
public string Incident2Startdate
public string Incident3Startdate
public string Incident1Closedate
public string Incident2Closedate
public string Incident3Closedate
Then the bounds checking so that no incident date can be BEFORE the start date, no incidentN close date can be earlier than the incidentN start date, common sense checking. How can it be coded up to say
if(Incident1Startdate < StartingDate)
{
Incident1Startdate = invalid;
Incident1Startdate.ErrorMessage.Show();
}
and then the same for all dates and the usual parameters that have to be within the bounds. Wonder if one of these other platforms like Angular or React or? take this into consideration and include as part of their framework for building a UI? So something like:
Make StartingDate < Incident1Startdate, Incident2Startdate, Incident3Startdate, (ErrorMessage="check the date");
Make Incident1Startdate < Incident1Stopdate;
Or each date field has to be manually coded. Which is fine, just didnt want to overlook some function that did this already
thanks!
Participant
1120 Points
372 Posts
Re: How to do Client side validation using model parameters?
Oct 14, 2020 03:27 AM|Jerry Cai|LINK
Hi,rogersbr
Sorry for the delay, to your first question ,I can use my demo well even I changed the type to 'string', can you offer your code so I can reproduce it?
And to your second question, I noticed that you have opened a new thread about it so I answerd you in that thread, hope it can help.
Best Regards,
Jerry Cai.