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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:59:52+00:00 2026-06-14T19:59:52+00:00

This should be an easy one, but without ViewState, I’m clueless here (I’ve been

  • 0

This should be an easy one, but without ViewState, I’m clueless here (I’ve been babied with WebForms for too long, I know!).

My scenario:

View

 @foreach (var product in Model.Products)
{
    <tr>
       <td>@Html.ActionLink("Compare", "Compare", new { id = product.ProductId })</td>
    </tr>
}

Controller

public ActionResult Compare(int id = 0)
{
        var product = SelectProduct(id); // selects the product from a list of cached products.

        if (product != null)
        {
           // _productDetails is a Model specifically for my View.
            _productDetails.ComparedProducts.Add(product);
        }

        return View("Index", _productDetails);
}

Obviously, when you click on “Compare” for each item, it’ll add to the the ComparedProducts list. But, with there being no ViewState, this will get cleared on every page refresh and lose the last product. I want products to be kept in this ComparedProducts list, but how?

I’m guessing they need to be appended to the querystring, so /Carousel/Compare/?id=2122,1221,1331,1333 etc. If so, how is this possible?

Thanks in advance.

Updated

If I did want to go the query string route, how do I do this?

I’ve tried:

<td>@Html.ActionLink("Compare", "Compare", new { id = product.ProductId, compared = Model.ComparedProducts.Select(a => a.ProductId) })</td>

But that brings out:

compared=System.Linq.Enumerable%2BWhereSelectListIterator`2[Product%2CSystem.Int32]

Which I’d expect really. I guess I’d make yet a further ViewModel property and simply store the Compared Id’s in there to not have much business logic within my View?

  • 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-14T19:59:53+00:00Added an answer on June 14, 2026 at 7:59 pm

    +1 for your relationship with webforms 🙂
    I think from now on, you can start to keep state in the other ways you already know from webforms like Session State: http://msdn.microsoft.com/en-us/library/ms178581(v=vs.100).aspx

    You are also right on the querystring, after all, if you want to keep things simple, is better to use the simplest methods , for instance:

    <url>?reference=123&compare=456
    

    EXAMPLE

    you need the first action as HttpGet and now this one as httpPOST

    [HttpPost]
    public ActionResult Compare(myModel model)
    {
    
        var product = SelectProduct(model.reference); // selects the product from a list of cached products.
    
        if (product != null)
        {
           // _productDetails is a Model specifically for my View.
           // you can always update the model you got in the first place and send it back
            model.ComparedProducts.Add(product); //
        }
    return View("Index", model);
    

    Your view should react according to empty properties to display

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I feel like this one should be easy but after numerous searches and attempts
This seems like this should be easy but I have not been able to
This should be and easy one for the LINQ gurus out there. I'm doing
This should be easy (at least no one else seems to be having a
This one should be easy. I just can't figure out what to search for...
Should be an easy one. I thought, from reading this blog post that I
This should be easy to find out but I can't seem to find it
It seems this should be easy but I'm having a lot of difficulty using
OK, I'm feeling like this should be easy but am obviously missing something fundamental
This should be an easy problem but... I need to format a currency for

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.