如何检查mvc -c#.net中字段的持久性 [英] how to check existency of a field in mvc -c#.net

查看:65
本文介绍了如何检查mvc -c#.net中字段的持久性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



我是MVC Pattern新手。我想检查一个字段是否存在。



Hi all

Iam new to MVC Pattern.I want to check a field exist or not.

@Html.TextBoxFor(m => m.employeeid)
@Html.ValidationMessageFor(m => m.employeeid)





当我输入文本框中的员工代码想要显示msg作为id存在,如果它已经存在于数据库中。



如何在mvc中使用任何客户端脚本执行此操作?



在此先感谢

Amritha



When i entered a employee code in textbox want to show msg as id exist if its already exist in database.

How to do this in mvc using any client side scripting ??

Thanks in Advance
Amritha

推荐答案

您可以使用 jQuery ajax 为此。



注意:只是一个指导。根据你的情况改变它。



JS



You can use jQuery ajax for this.

Note:Just a guidance.Change it according to your scenario.

JS


.ajax({
url:/ Portal / IsEmployeeExist,
类型:'获取',
数据类型:json,
ca che:false,
data:{empId:passYourEmpId},
success:function(data){
if(!data){
// your message
}
},
错误:function(xhr,ajaxOptions,thrownError){
//
}
});
.ajax({ url: "/Portal/IsEmployeeExist", type: 'Get', dataType: "json", cache: false, data: { empId: passYourEmpId}, success: function (data) { if (!data) { //your message } }, error: function (xhr, ajaxOptions, thrownError) { // } });





行动方法





Action method

[HttpGet]
       public JsonResult IsEmployeeExist(string empId)
       {
           var isEmployeeExist = //here do your db validation and return true or false;

           return Json(isEmployeeExist, JsonRequestBehavior.AllowGet);
       }





以下是关于此的精彩视频:在ASP.NET中使用jQuery和Ajax的实践MVC应用程序


这篇关于如何检查mvc -c#.net中字段的持久性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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