开发者

Customizing Model Validation Feedback

I want to change the way a validation message appears to the user in my nopCommerce web application. Currently, it appears as so:

Customizing Model Validation Feedback

I want to change that, so that if and when the login credentials are incorrect, the input fields get a red border, an开发者_StackOverflowd the text [ wrong credentials ] to be set as Placeholder for the input fields.

I tried disabling the code:

@Html.ValidationSummary(true, T("Account.Login.Unsuccessful").Text)

But that just took away all validation feedback. How can I achieve what I mentioned above?


Here is the complete Updated code

CSS

.validation-error
{
    border: 1px solid #ff0000;
    background-color: #ffeeee;
}

Jquery code to check the login using $.ajax

$(function () {
        $('#btnLogin').click(function (e) {
            var email = $('#Email').val(); // this your username textbox value
            var password = $('#Password').val(); // this is your password textbox value
            var postdata = 
            {
                "Email": email,
                "Password": password
            };
            $.ajax({

                tyep: 'POST',
                url: '@Url.Action("LogIN","Account")', // your controller action will be called to check for the login details
                data: postdata, // this data you have to post to controller for validation
                success: function(value) { // if ajax call complete, controller action will return boll value true here 
                     if(valeu) {
                    $('#divLoginError').addClass("validation-error"); // this will add class class to your textboxes with red broder
                    $('divLoginError').html('Please check your username / password');
                     }
                  },
                error: function(errorData) // if any error while calling Ajax. this method is gonna call
                {
                    $('#divLoginError').show().html(errorData);
                }
            });

        });
    });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜