Ich bin neu in MVC4. Hier habe ich die ModelState.AddModelError-Nachricht hinzugefügt, die angezeigt werden soll, wenn der Löschvorgang nicht möglich ist.
Wie ModelState.AddModelError Nachricht hinzufügen, wenn Modellelement nicht verknüpft ist
<td>
<a id="aaa" href="@Url.Action("Delete", "Shopping", new { id = Request.QueryString["UserID"], productid = item.ProductID })" style="text-decoration:none">
<img alt="removeitem" style="vertical-align: middle;" height="17px" src="~/Images/remove.png" title="remove" id="imgRemove" />
</a>
@Html.ValidationMessage("CustomError")
</td>
@Html.ValidationSummary(true)
In meinem Controller
public ActionResult Delete(string id, string productid)
{
int records = DeleteItem(id,productid);
if (records > 0)
{
ModelState.AddModelError("CustomError", "The item is removed from your cart");
return RedirectToAction("Index1", "Shopping");
}
else
{
ModelState.AddModelError(string.Empty,"The item cannot be removed");
return View("Index1");
}
}
Hier habe ich nicht eine des Modellelementes in der Ansicht übergibt für das Element im Modell zu überprüfen, und ich konnte nicht die Modelfehlermeldung.
Alle Vorschläge