Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8694735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:51:18+00:00 2026-06-13T00:51:18+00:00

I am new to MVC4. Here I added the ModelState.AddModelError message to display when

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:51:20+00:00Added an answer on June 13, 2026 at 12:51 am

    The ModelState is created at each request so you should use TempData.

    public ActionResult Delete(string id, string productid)
    {             
        int records = DeleteItem(id,productid);
        if (records > 0)
        {    
            // since you are redirecting store the error message in TempData
            TempData["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");
        }
    }
    
    public ActionResult Index1()
    {
        // check if TempData contains some error message and if yes add to the model state.
        if(TempData["CustomError"] != null)
        {
            ModelState.AddModelError(string.Empty, TempData["CustomError"].ToString());
        }
    
        return View();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If you create a new MVC4 web application with the Internet Application Project Template
In ASP.net MVC4 there's this 'new' concept of a web API for exposing CRUD
I've created a method using the new WebAPI features in MVC4 and have it
I am trying to use the JsonArray class in a new empty asp.net mvc4
i am new to asp.net MVC4 architecture i am get stuck with following thing
I am new to ASP.NET MVC4. I would like to ask if how can
This will be my first question here! Im having problems with my mvc4 app
I noticed when the MVC4 beta was announced, it includes a new Web-API .
I am using the new mvc4 ajax controller template and I don't know how
Here's the situation: I have a great big text input box for a URL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.