2011-09-24 46 views
0

我想改变验证消息在我的nopCommerce Web应用程序中向用户显示的方式。目前,它看起来像这样:定制模型验证反馈

enter image description here

我想改变这种状况,使如果&当的登录凭据不正确,输入字段得到红色边框,和文本[错误的凭据]被设置为占位符为输入字段。

我尝试禁用代码:

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

但是,这只是拿走了所有的验证反馈:(我如何能实现我上面提到的,我将不胜感谢所有帮助

谢谢你

回答

0

这里是完整的更新代码

CSS

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

jQuery代码使用$就

$(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

由于帕特尔查看登录的,但是当登录无效,我没有得到[验证错误]类应用到我的文字输入! – Ciwan

+0

验证失败后,您可以将该类应用于文本框..查看我更新后的代码... –

+0

Ahh OK,但是如果验证失败,如何通过jQuery检查?有没有布尔? – Ciwan