asp.net mvc - MVC Remote Validation With Additional bool Fields -



asp.net mvc - MVC Remote Validation With Additional bool Fields -

i trying utilize remote validation additional bool checkbox field

[remote("isstorageconnectionvalid", "tenantmanagement", additionalfields = "createstorage")] public string storageconnectionstring { get; set; }

validation code

public jsonresult isstorageconnectionvalid(string storageconnectionstring, bool createstorage){

it works in terms of hitting validator. createstorage true irrespective of value of checkbox. if utilize additional fields aren't check boxes supplied perfectly.

checkbox created standard:

@html.checkboxfor(m => m.createstorage)

is bug? or doing wrong?

fiddle here (is mvc4 think same thing)

it appear bug when used @html.checkboxfor. problem checkboxfor renders 2 elements, checkbox value="true" , hidden input value="false" (unchecked checkboxes not post sec hidden input ensures value posted utilize defaultmodelbinder)

looking @ relevant section of jquery.validate.unobtrusive.js file

adapters.add("remote", ["url", "type", "additionalfields"], function (options) { var value = { url: options.params.url, type: options.params.type || "get", data: {} }, prefix = getmodelprefix(options.element.name); $.each(splitandtrim(options.params.additionalfields || options.element.name), function (i, fieldname) { var paramname = appendmodelprefix(fieldname, prefix); value.data[paramname] = function () { homecoming $(options.form).find(":input[name='" + escapeattributevalue(paramname) + "']").val(); }; }); setvalidationvalues(options, "remote", value); });

the return statement returns (in case) .find(':input[name="createstorage"]').val(); returns value of first input name="createstorage" true (the value of checkbox)

as test, if render value using hiddenfor rather checkboxfor receive right value in isstorageconnectionvalid method (but of course of study help since cant alter value)

not sure of best solution, unobtrusive script should first checking if .find(..) returns more 1 element, if first checkbox unchecked, returning value of sec element.

edit

i have reported issue @ codeplex

edit 2

i have been advised the issue has been fixed here

asp.net-mvc asp.net-mvc-5 unobtrusive-validation asp.net-mvc-5.2

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -