at model in asp.net mvc app, used requiredif attributes.
model
[requiredif("customertype== 'b'", errormessage = "please enter customer name")] [display(name = "customer name")] [datamember(name = "customername")] public string customername{ get; set; } [required(errormessage = "please select customer type")] [display(name = "customer type")] [datamember(name = "customertype")] public string customertype { get; set; }
view
@using (html.beginform(null,null,formmethod.post,new { @class ="transactionform" })){ <td>@html.labelfor(model => model.customername, htmlattributes: new { @class = "control-label col-md-2" })</td> <td>@(html.kendo().textbox() .name("musteriad") .htmlattributes(new { style = "width: 250px; height: 32px;" })) @html.validationmessagefor(model => model.customername, "", new { @class = "text-danger" }) </td>
i sending form server via ajax post, , here function;
function saverecord(action, controller, param) { $('.error').remove(); var form = $(".transactionform"); var validator = form.kendovalidator().data("kendovalidator"); if (validator.validate()) { var data = form.serialize(); $.ajax({ url: '/' + controller + '/' + action, datatype: 'json', type: 'post', data: data, success: function (response) { if (response !== null && !response.success) { displayerrors(response.error); } else { } }, error: function (xhr, ajaxoptions, thrownerror) { } }); } }
well structure, handle server side validation perfect, on client side - validator.validate()
section, validate input required attributes.
should write code client side validation of these requiredif inputs or there other ways handle @ razor side or js side?
i think there no way handle leaving kendo-ui. because, kendo produces html customer type input;
<input data-val="true" data-val-required="please enter customer name" id="customertype" name="customertype" style="width: 250px; display: none;" type="text" data-role="dropdownlist" class="k-valid">
and customer name
<input class="k-textbox k-valid" id="customername" name="customername" style="width: 250px; height: 32px;">
data-val-required
not produced requiredif attributed member kendo.
so, checking these fields @ server side.
Comments
Post a Comment