I am new to MVC4. Here I added the ModelState.AddModelError message to display when the delete operation is not possible.
<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 my 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");
}
}
Here I didnt pass any of the model item in the View to check for the item in Model and I couldnt get the ModelState error message ..
Any suggestions