asp.net mvc 4 - Kendo ui - how to tie validation to mvc model attributes -
from reading posts in thread - , being unable post question there bizarre reason :( ask here in hope of getting solution
am write in saying have validation below..
- i add html5 attribute (data-required-msg/validationmessage) textbox , required attribute well..
- i make span invalid msg , tie field "data-for" attribute. message "please enter name" should appear in span then.
questions
- is way work this?
- is there no way me display proper error message ("error message want show"), in way tie mvc attributes on viewmodel. poster said lot more scalable/re-usable , better design.
using data-for="name" brittle change in model field name not reflect there , forgotten hence delivering buggy software. losing type safety of
@html.validationmessagefor(m=> m.name)
code
public class aviewmodel { [required(errormessage="error message want show")] public string name { get; set; } } <div class="validation-wrapper"> <div class="input-wrapper"> @html.textboxfor(m => m.name, new { placeholder = "eg. john smith", data_required_msg="pleaseenter name", required="required" } ) </div> <span class="k-invalid-msg" data-for="name"></span> </div>
cheers, j
in order able saying, need using kendo ui asp.net mvc. can continue using dataannotations attributes , html.validationmessagefor() helpers before. need call $('[your_form_selector]').kendovalidator()
after form (or on document.ready()).