Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi to all,
compare date if one fields name delivery date and another field name posting date.
Now i want to check delivery date is greater than posting date.how to compare using mvc.
What condition shall i want to use and where i write condition in controller or model or views
Posted
Updated 9-Dec-14 0:19am
v2
Comments
Vi(ky 9-Dec-14 6:22am    
You can write the code where you writing the business rules.
JOTHI KUMAR Member 10918227 9-Dec-14 6:26am    
i cant caught you .here i asked simply where to write condition what condition we want to use .bcz here i compare when we move to next field

1 solution

Normally you should do the validation of your two dates on the client (in the View), so in order to do that you should do the next staps:

1)Define a custom validation attribute class;

2)Mark you both DateTime properties from your model with this attribute;

3)Update the view to use validation for both properties by using @Html.ValidationMessageFor().

You can see details here: https://code.msdn.microsoft.com/Build-Custom-Data-840477b9[^]
 
Share this answer
 
Comments
JOTHI KUMAR Member 10918227 9-Dec-14 7:06am    
above three step i done it now i want to check like remote validation or using script
Raul Iloc 9-Dec-14 8:09am    
The standard validation in MVC by using "@Html.ValidationMessageFor()", like I also suggested in my solution, is done on the client (directly in the browser) and is using standard validation scripts: jquery.validate.min.js and "jquery.validate.unobtrusive.min.js" that must be added in your view or in your used layout. So there is no remote validation involved here!
JOTHI KUMAR Member 10918227 9-Dec-14 8:24am    
hey here i add all validate (js file) in layout.cshtml and @html.validation also added in Index.cshtml.Here i want to check start and end date (end date must be greater than start date)
JOTHI KUMAR Member 10918227 9-Dec-14 8:28am    


<div class="row form-group">
<div class="col-md-4">

StartDate
</div>
<div class="col-md-8">
@Html.TextBoxFor(model => model.goodreceipt.StartDate, new { @Value = DateTime.Now.ToString("dd/MM/yyyy"), @class = "form-control control-text datePicker", @id = "IssueDate",@onkeyup = "OnChangeDate();" })
@Html.ValidationMessageFor(model => model.goodreceipt.StartDate)
</div>
</div>

<div class="row form-group">
<div class="col-md-4">

EndDate
</div>
<div class="col-md-8">
@Html.TextBoxFor(model => model.goodreceipt.EndDate, new { @Value = DateTime.Now.ToString("dd/MM/yyyy"), @class = "form-control control-text datePicker", @id = "IssueDate",@onkeyup = "OnChangeDate();" })
@Html.ValidationMessageFor(model => model.goodreceipt.EndDate)
</div>
</div>
JOTHI KUMAR Member 10918227 9-Dec-14 8:29am    
here i used this now i need to know how to compare end date greater than start date condition.where to write but i need to write in script. so anyone refer me write a code in script

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900