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

[Solved] Validations in Grid Columns

3 Answers 77 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Daryl Shenner
Top achievements
Rank 1
Daryl Shenner asked on 20 Jan 2012, 11:59 AM
Hi, I've a problem with validating the column values in the Grid

I've StartTime and EndTime Column in my MVC Grid.

I'd like to check whether the value in the StartTime Column is less than the EndTime column. I checked with my model class whether I  have any property to compare/Check the values. But I don't find

Here is how I designed my model : Model File Name: AppointmentModels

[DataType(DataType.DateTime)]
public DateTime? StartTime { get; set; }

[DataType(DataType.DateTime)]
public DateTime? EndTime { get; set; }

I tried with Remote Attribute of the Model Property.

[Remote("IsDateLesser", "Opportunity", AdditionalFields = "EndTime")]
[DataType(DataType.DateTime)]
public DateTime? StartTime { get; set; }

Whenever I click the calendar the "IsDateLesser" method is been raised, which I don't like to have.  It should raise only when I select the value from the calendar. And also, I'd like to send a modal property as the parameter to the IsDateLesser method.

Below is my IsDateLesser  method.  EndTime value is always null,

 public JsonResult IsDateLesser(AppointmentModels model)
        {
            if (model.StartTime != null && model.EndTime != null)
            {
                var obj = model.StartTime;
                var obj1 = model.EndTime;
                return Json(true, JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(false, JsonRequestBehavior.AllowGet);
            }
        }


Any help would be appreciated. !!

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 24 Jan 2012, 02:27 PM
Hi Daryl,

There isn't any build in DataAnnotation attribute that is suitable for comparing dates. However, the MVC Foolproof Validation library provides the GreaterThan attribute which can be used for this purpose.

Greetings,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Daryl Shenner
Top achievements
Rank 1
answered on 26 Jan 2012, 02:25 AM
Hi,

 Thanks for that. It really worked as expected but except one. I don't get the error message in my grid when the validation fails. If my start time is great than the end time, then it should be conveyed to the user.

Can you help me on this. Thanks
0
Daniel
Telerik team
answered on 27 Jan 2012, 01:07 PM
Hello Daryl,

I am not sure what may be preventing the messages from showing. When I tried it locally, everything worked as expected.
I attached a sample project which uses the GreaterThan attribute to compare dates. Could you check it and see if I missed something?

Regards,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
Tags
Grid
Asked by
Daryl Shenner
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Daryl Shenner
Top achievements
Rank 1
Share this question
or