This helped alot. In my case it was a table, where updates were also possible. In this case the above solution doesn't work. So I wanted to share my solution for this case.
In the solution below, I added an additional field to pass to the Controller(The Primary Key of the Model).
Then in the controller I am checking if the Primary Key is given.
If so, we know, that we came from the update site since it's the only case where we already have an ID in the model. The last step is to check if the string and the primary key is the same. If they both are, it's ok, because we didn't change anything in the string. If only the string is the same but not the ID, it means, that we changed the string and changed it to another existing items string, so we return false.
Model:
[Key]
[Display(Name = "Idee ID")]
public int intIdeaID { get; set; }
[Required(ErrorMessage = "Dieses Feld muss ausgefüllt werden")]
[Display(Name = "Idee")]
[Remote("ideaExists", "TabIdea", HttpMethod = "POST", ErrorMessage = "Es wurde bereits eine Idee mit dieser Bezeichnung erstellt", AdditionalFields = "intIdeaID")]
public string strIdea { get; set; }
Controller:
[HttpPost]
public JsonResult ideaExists(string strIdea, int? intIdeaID)
{
if (intIdeaID != null)
{
if (db.tabIdea.Any(x => x.strIdea == strIdea))
{
tabIdea existingTabIdea = db.tabIdea.Single(x => x.strIdea == strIdea);
if (existingTabIdea.intIdeaID != intIdeaID)
{
return Json(false);
}
else
{
return Json(true);
}
}
else
{
return Json(true);
}
}
else
{
return Json(!db.tabIdea.Any(x => x.strIdea == strIdea));
}
}