How can I use jquery remote validation validation in ASP.NET web forms?

I have searched everywhere and I cannot find a convincing example.

Does anyone do this? Can someone provide an example of invoking remote validation using the JQuery validation plugin via WebMethod on an aspx page (web forms)?

+3
source share
2 answers

I think the reason that the code gives you a bad taste is because writing json as strings is pretty smelly. One minor improvement would be to create a real JSON object and then use the JSON.stringify (...) function.

json-,

var customerInput = {"customerToAssignTo":$("#customerToAssignTo").val()};
var serializedCustomerInput = JSON.stringify(customerInput );

data: "{'customerToAssignTo':'" + $("#customerToAssignTo").val() + "'}"

data: serializedCustomerInput

https://github.com/douglascrockford/JSON-js/blob/master/json2.js

:

http://www.json.org/js.html

http://msdn.microsoft.com/en-us/library/cc836459(VS.85).aspx - Windows,

+3

, , , . Json, .

var validated = $("#aspnetForm").validate(
    {
        rules:
        {
            customersToReassign:
            {
                required: true
            },
            customerToAssignTo:
            {
                required: true,
                remote: 
                {
                    url: window.location + "/IsValidCustomer",
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    data: "{'customerToAssignTo':'" + $("#customerToAssignTo").val() + "'}"
                }
            }
        },
+1

Source: https://habr.com/ru/post/1754345/


All Articles