Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have been using kendo Ui in mvc 3.0 and I am pretty comfortable with that. Recently, I switched in MVC 4 and the main problem I found in this is I am unable to validate kendo controls using MVC model validations(Data Annotations). Please help me regarding validating Kendo Date picker by java script or by model based Validations.I do not want to use kendo validators.I am basically trying to validate like this.

Code

In model:

[Required] //and others bla bla
public string Date {get;set;}

In cshtml page:

@(Html.Kendo().DatePicker()  
    .Name("datepicker")  
    .Value("10/10/2011")  
    .HtmlAttributes(new { style = "width:150px" })  
)  

@Html.HiddenFor(m => m.Date);

Now at the submit click, I will assign value to hidden field:

OnSaveClick()
{
    document.getelementbyId('Date ').value=$("#datepicker).val();
}

Value of datepicker will automatically assign to hidden field and if date picker is empty, then validation on hidden field will fire.

This concepts work in MVC 3.0 but not in MVC 4.0. Please help me. Thanks for paying attention.

share|improve this question
    
First off, I don't think you're going to find the "Date" field with Javascript, since you are searching for "Date " instead of "Date". Secondly, your jQuery selector is invalid. It needs to be $("#datepicker").val(). Note that you missed a double quote in there. –  JohnDubya Jul 22 '13 at 23:07
add comment

1 Answer

up vote 0 down vote accepted

There are many techniques to do validations. you can create your own attributes or just try to use Java script code of kendo where ever you get problems because script code has it's easy availbility and we can validate with script also . One another thing you can also do the validations by java script like on button click just do

{
  var date= $("datepicker").val();

}

This will get your date picker value into your date variable and now you can do it scripting with using spliting and keep every split array value in another objects like keep date seperate and then month seperate and then year seperate. check them differently by script and return false where ever it is wrong otherwise return true.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.