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 8770087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:29:19+00:00 2026-06-13T17:29:19+00:00

I am displaying a shopping cart. I need to check for empty values in

  • 0

I am displaying a shopping cart. I need to check for empty values in Shopping cart and display a message like “The Shopping Cart is empty”.

When I use ModelState.AddModelError in myAction, it throws an exception as there is null reference in Model. How to display the ErrorMessage.
My Action

  public ActionResult Index()
        {
            string id = Request.QueryString["UserID"];
            IList<CartModel> objshop = new List<CartModel>();
            objshop = GetCartDetails(id);
            if (objshop.Count > 0)
            {
                return View(objshop.ToList());
            }
            else
            {
                ModelState.AddModelError("", "Your Shopping Cart is empty!");
            }
            return View();
}

My View

    @{
         @Html.ValidationSummary(true)
     }

 <th > @Html.DisplayNameFor(model => model.ProductName) </th>
 <th > @Html.DisplayNameFor(model => model.Quantity)   </th>
 <th > @Html.DisplayNameFor(model => model.Rate)      </th>
 <th > @Html.DisplayNameFor(model => model.Price)    </th>        
 @foreach (var item in Model)
   {
<td>  @Html.DisplayFor(modelItem => item.ProductName)</td>
<td>  @Html.DisplayFor(modelItem => item.Quantity)</td>
<td>  @Html.DisplayFor(modelItem => item.Rate) </td>
<td>  @Html.DisplayFor(modelItem => item.Price) </td>
   }

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-13T17:29:21+00:00Added an answer on June 13, 2026 at 5:29 pm

    Change the last line in your Action like this:

    return View(new List<CartModel>());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am displaying a partial view (shopping cart) inside my main (pricing view) view
I am currently working with check boxes and displaying values based on the values
I'm having troubles with displaying product information in shopping cart page. please point out
I'm making shopping cart, and I have s problem displaying the products. Here's a
When displaying all articles of a specific month (given through the urls like this
It appears like something is stopping my errors from displaying normally an in ASP.NET
I'm writing a shopping cart application for a family member's online seed business. It's
These are the two actionresults I use for my cart: The first action I
If it helps, I'm using Opencart shopping cart & I am after showing an
I have a GridView in ASP which I use for displaying products in a

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.