Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc Can';不编辑唯一值_Asp.net Mvc - Fatal编程技术网

Asp.net mvc Can';不编辑唯一值

Asp.net mvc Can';不编辑唯一值,asp.net-mvc,Asp.net Mvc,我在编辑数据方面有一些困难。我有一些财产——ISBN。我认为它具有独特的价值。当我创建新数据时,它是可以的,但当我尝试编辑时,它会将已经在使用的数据写入。我能做什么 教材: [Remote("IsISBNExists", "Book", ErrorMessage = "ISBN number is already in use")] public string ISBN { get; set; } 图书管理员: public JsonResult IsISBNExists(string Isb

我在编辑数据方面有一些困难。我有一些财产——ISBN。我认为它具有独特的价值。当我创建新数据时,它是可以的,但当我尝试编辑时,它会将已经在使用的数据写入。我能做什么

教材:

[Remote("IsISBNExists", "Book", ErrorMessage = "ISBN number is already in use")]
public string ISBN { get; set; }
图书管理员:

public JsonResult IsISBNExists(string Isbn) {
    return Json(!bookContext.Books.Any(x => x.ISBN == Isbn), JsonRequestBehavior.AllowGet);
}

您可以包括正在编辑的记录的ID,并使用该ID确定ISBN是否正在使用

只需在AdditionalFields参数中添加您的Book ID字段,即可将其包含在验证请求中

[Remote("IsISBNExists", "Book", AdditionalFields = "BookID", ErrorMessage = "ISBN number is already in use")]
public string ISBN { get; set; }
然后在验证中使用该字段

public JsonResult IsISBNExists(string Isbn, int BookID) {
    return Json(!bookContext.Books.Any(x => x.BookID != BookID && x.ISBN == Isbn), JsonRequestBehavior.AllowGet);
}