c# - Validation not worked on kendoUI multiselect -
i creating form using mvc4. here used kendo multiselect , try validate through model annotation.
my code :
@model webapp._2012.models.deviceinventory.devicetechnologymodel <script src="~/scripts/jquery.validate.unobtrusive.min.js"></script> @using (ajax.beginform("create", "device_technologyinventory", new ajaxoptions { httpmethod = "post", onsuccess = "onsuccessaddtechnology" })) { @html.validationsummary(true) <table width="100%" cellspacing="0" cellpadding="0" border="0"> <tr> <td> <@html.labelfor(model=>model.name)</td> <td class="editor-field" width="160px;"> @html.editorfor(model => model.name) @html.validationmessagefor(model => model.name) </td> </tr> <tr> <td>@html.labelfor(model => model.alias)</td> <td class="editor-field"> @html.editorfor(model => model.alias) @html.validationmessagefor(model => model.alias) </td> </tr> <tr> <td>@html.labelfor(model => model.vendors)/td> <td class="editor-field"> @(html.kendo().multiselectfor(model=>model.vendors) .name("vendors").placeholder("select") .bindto(new selectlist(viewbag.vendorlist, "value", "text")) ) @html.validationmessagefor(model => model.vendors) </td> </tr> </table> <div class="createwrp"> <input type="submit" value="create " class="btn-success"/> <input type="reset" value="reset " class="btn-primary" /> </div>
my model :
public class devicetechnologymodel { public int id { get; set; } [required(errormessage = "*")] [display(name = "device technology")] public string name { get; set; } [required(errormessage = "*")] [display(name = "alias")] public string alias { get; set; } [required(errormessage = "*")] [display(name = "device vendors")] public list<string> vendors { get; set; } }
when clicked on submit button validation error message appear on both "name" , "alias" field not on field "vendors".
i not want use javascript
validation.
you need validate value not list object.
you may need make below changes in model:
public class devicetechnologymodel { public int id { get; set; } [required(errormessage = "*")] [display(name = "device technology")] public string name { get; set; } [required(errormessage = "*")] [display(name = "alias")] public string alias { get; set; } [required] [required(errormessage = "*")] [display(name = "device vendors")] public int vendorid { get; set; } public list<string> vendors { get; set; } }
in view:
<tr> <td>@html.labelfor(model => model.vendors)/td> <td class="editor-field"> @(html.kendo().multiselectfor(model=> model.vendorid) .name("vendors").placeholder("select") .bindto(new selectlist(viewbag.vendorlist, "value", "text"))) @html.validationmessagefor(model => model.vendorid) </td> </tr>
make sure when submit form vendorid
property holds value or not.
if has nothing validation should work.
hope helps.
Comments
Post a Comment