我如何更新,如果在Db中有相同的数据,我想要显示验证“名称已经存在!”。 [英] How Do I Do When I Did Update If There R Same Data In Db I Want To Show Validation "Name Already Exists!".
本文介绍了我如何更新,如果在Db中有相同的数据,我想要显示验证“名称已经存在!”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
private void UpdateInfo(PersonTypeInfo persontypeinfo)
{
var info = db.mPersonTypeInfo.Find(persontypeinfo.typeid);
//info = db.mPersonTypeInfo.Find(persontypeinfo.description);
//PersonTypeInfo typeinfo = db.mPersonTypeInfo.FirstOrDefault(obj => obj.typeid == persontypeinfo.typeid & obj.description==persontypeinfo.description);
try
{
if (info.typeid!=null)
{
ViewData["result"] = GeneralConstant.Duplicate_Msg1;
}
else
{
bindObject(persontypeinfo, "u");
((IObjectContextAdapter)db).ObjectContext.Detach(typeinfo);
db.Entry(persontypeinfo).State = EntityState.Modified;
db.SaveChanges();
ViewData["result"] = GeneralConstant.Update_Msg;
}
}
catch
{
ViewData["result"] = GeneralConstant.Update_Fail_Msg;
}
}
推荐答案
你可以做得更好在javascript中。当在文本框中填写名称时,通常在聚焦的那一刻,用户应该收到一条消息,表示已经使用了userName,请使用unique或尝试使用其他userName。
为此,你可以看一下进入下面的小提琴:
小提琴 [ ^ ]
关注焦点功能,你需要指定或添加一个ajax调用给发回的服务器一个布尔值,表明userName是否已存在。比如
You can better do that in the javascript. When the Name is filled in the Textbox, usually at that moment on focusout the user should get a message that userName has already been taken please use unique or try with another userName.
For doing that you can look into the below fiddle:
Fiddle[^]
on focusout function, you need to specify or add an ajax call to the server sending back a boolean value suggesting if the userName already exists or not. Like
.ajax({
type: GET,
url: / SERVERURL,
成功:函数(响应){
如果(response == false ){ // 来自服务器的布尔响应
.ajax({ type:"GET", url:"/SERVERURL", success: function(response){ if(response==false){ //boolean response from the server
( #IDOFSPAN)。text(' 抱歉用户名已经被); // 验证文本的span id
("#IDOFSPAN").text('Sorry username already taken'); //span id for the validation text
这篇关于我如何更新,如果在Db中有相同的数据,我想要显示验证“名称已经存在!”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文