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

The Archive Base Latest Questions

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

I’m just getting into MVC properly, and I’m stuck on a concept which I

  • 0

I’m just getting into MVC properly, and I’m stuck on a concept which I figured would be relatively simple.

So, I have a form, in which posts to a Controller (which is fine), at the minute I have:

Controller

public ActionResult TestAction(int productId)
{
    // What to do here... ?
    return View();
}

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult TestAction(FormCollection values)
{
    // Do work here and return the objects
    return View(Products);
}

View

@foreach (var product in Model)
            {
                <tr>
                    <td>@product.Provider.Name</td>
                    <td>&pound;@product.MonthlyPremium</td>
                    <td>@Html.ActionLink("More Details", "TestAction", new { productId = product.ProductId })</td>
                    <td>Compare</td>
                </tr>
            }

// I want the singular product details to be displayed here, under the product list... but how?!

Now, what I want is when you click on “More Details” (the ActionLink) then the product details are going to be displayed, which are part of the singular Product objects. I got the TestAction controller being called from GET, but how do I retain the view of the products and display the details of the singular product? Assign this singular Product to the ViewBag and do it that way? Then, for the list of products, cache the original list and use that cache?

I want this done via postbacks as this is for the non-JS version of my site.

Surely there has to be a better way of doing this, or have I been babied with ViewState for too long?

  • 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-14T17:37:01+00:00Added an answer on June 14, 2026 at 5:37 pm

    You could add a property to your model, for example bool ViewDetail, and set that in your controller for the item that corresponds to the productId parameter:

    public ActionResult TestAction(int productId)
    {
        // TODO: error checking
        Products.Single(m => m.ProductId == productId).ViewDetail = true;
        return View(Products);
    }
    

    And display it on your view:

    var productDetail = Model.SingleOrDefault(m => m.ViewDetail == true);
    if (productDetail != null)
    {
        // Display product details
    }
    

    Or you could alter your model to contain:

    public class ProductsWithDetailModel
    {
        public IEnumerable<Product> Products { get; set; }  // to loop over and display all products
        public Product DetailProduct { get; set; }          // to display product details, if not null
    }
    

    Then again, set the DetailProduct based on the productId parameter, and display it in the view if it is not null.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a text area in my form which accepts all possible characters from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I would like to run a str_replace or preg_replace which looks for certain words
I have a French site that I want to parse, but am running into
I have an autohotkey script which looks up a word in a bilingual dictionary
I have an array which has BIG numbers and small numbers in it. I
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;

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.