如何从MVC中的资源文件中获取客户端验证消息? [英] How to client side validation message from resource file in MVC?

查看:51
本文介绍了如何从MVC中的资源文件中获取客户端验证消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< label class =for =form-last-name> @ Resources.Registration.FirstName * < / label>

@ Html.TextBoxFor(model => model.FirstName)







< label class =for =form-email> @Resources .Registration.LastName * < / label>

@ Html.TextBoxFor(model => model.LastName)





< label class =for =form-email> @ Resources.Registration.Address * < / label>

@ Html.TextBoxFor(model => model.Address)





< button type =submitclass =btn>提交< / button>



< script type =text / javascript>
函数PageValidate(){

if($('#FirstName')。val()==''|| $('#FirstName')。val()== null){

$(#firstName)。html('名字是必需的');

$('#FirstName')。focus();

返回false;

}

else {

$(#firstName)。html(' ');

} < br $>


if($('#LastName')。val()==''|| $('#LastName')。val()== null){



$(#lastName)。html('姓氏是必需的');

$('#LastName')。focus();

返回false;

}

else {

$(#lastName)。html(' ');

}



if($('#Address')。val()== null || $('#Address')。val()==''){

$(#addresses)。html('地址是必需的');

$('#A ddressLine1')。focus();

返回false;

}

else {

$(#地址)。html(' ');

}



}

< / script>



我尝试了什么:



在视图页面中 -



@ Resources.Registration.FirstName正在运行但是,

在javascript错误消息中没有working-:

$(#firstName)。html(' @ Resources.Registration.errorFirstName ');



请解决此问题

解决方案

('#FirstName')。val()==''||

('#FirstName')。val()== null){


(#firstName)。html('名字是必需的');


<label class="" for="form-last-name">@Resources.Registration.FirstName*</label>
@Html.TextBoxFor(model => model.FirstName)




<label class="" for="form-email">@Resources.Registration.LastName*</label>
@Html.TextBoxFor(model => model.LastName)



<label class="" for="form-email">@Resources.Registration.Address*</label>
@Html.TextBoxFor(model => model.Address)



<button type="submit" class="btn" >Submit</button>

<script type="text/javascript>
function PageValidate() {
if ($('#FirstName').val() == '' || $('#FirstName').val() == null) {
$("#firstName").html('First name is required');
$('#FirstName').focus();
return false;
}
else {
$("#firstName").html('');
}

if ($('#LastName').val() == '' || $('#LastName').val() == null) {

$("#lastName").html('Last name is required');
$('#LastName').focus();
return false;
}
else {
$("#lastName").html('');
}

if ($('#Address').val() == null || $('#Address').val() == '') {
$("#addresses").html('Address is required');
$('#AddressLine1').focus();
return false;
}
else {
$("#addresses").html('');
}

}
</script>

What I have tried:

In view page-

@Resources.Registration.FirstName is working but,
In javascript error message are not working-:
$("#firstName").html('@Resources.Registration.errorFirstName');

Please solve this problem

解决方案

('#FirstName').val() == '' ||


('#FirstName').val() == null) {


("#firstName").html('First name is required');


这篇关于如何从MVC中的资源文件中获取客户端验证消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆