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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:50:30+00:00 2026-05-25T00:50:30+00:00

In my ASP.net MVC App (using Razor views) I have a ProductDetails view. This

  • 0

In my ASP.net MVC App (using Razor views) I have a “ProductDetails” view.
This retrieves a “Product” model from the database.

The Product object, has a collection of “ProductVariation” (size, price, inStock etc…)

Something like this:

public class Product()
{
  public int ID { get; set; }
  public str Name { get; set; }

  public ICollection<ProductVariation> Variations { get; set; }
}

public class ProductVariation
{
  public int VariationID {get;set;}
  public bool ProductID {get;set;}
  public bool InStock {get;set;}
  public double Price {get;set;}
}

(Obviously this is a very cut down model)

On my ProductDetails view, I have a dropdown to be able to select a variation.

What I want to be able to do is show / hide elements based on the selection.

Currently, I’ve got the price updating etc.. using jQuery.
I do this by creating a series of tags with an id such as “1234-price”
(1234 representing the VariationID)

The value of my select element is the VariationID
So, i basically use a jQuery selector to get the value of the ID i want to show, and hide all the others.
This is working fine.

However, if a product is not available (ie InStock is false) I want to hide the “buy” button, and display some out of stock text.

How can I go about doing something like this?

Should I create an array of Javascript “product” objects on the page, from the model returned by my controller?

Is there a better way?

  • 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-05-25T00:50:31+00:00Added an answer on May 25, 2026 at 12:50 am

    Based on what you’re describing, using a templating system, such as this: http://api.jquery.com/category/plugins/templates/

    First, you would make a javascript object that reflects your database model. For example…. (ideally, this would be automatically generated with something like:

    <script>
      var viewModel = @Html.Raw(JsonNetConverter.Serialize(Model))
    </script>
    

    However you go about generating that, you should end up with something like this:

    var viewModel = { VariationID: 1, ProductID: 1, InStock: true, Price: 9.99 };
    

    In your dropdown menu where users can select product variations, you would do something like this:

    <select name="ProductVariations">
        <option value="1">Variation 1</option>
        <option value="2">Variation 2</option>
    </select>
    

    You would then need to make an action in your controller, like:

    [HttpPost]
    public ActionResult GetVariationById(int id)
    {
        var model = new VariationModel();
        var variation = model.getVariationById(id);
        return View(variation);
    }
    

    Finally, you re-render your template with the new data you got back from your model:

    $("#view-template").tmpl(viewModel).appendTo("#selector");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

'm using ASP.NET MVC 3 with Razor views. I have a partial view which
I have an ASP.NET MVC 3 app hosted on IIS. This app is using
I'm sending an email from my ASP.NET MVC app using the Spark View Engine
I have an Asp.Net MVC app using jqGrid. Can I send the Model that
I'm using ASP.NET MVC 3, with Razor views. I have two action methods (Get
For my ASP.NET MVC 3 app (using Razor) my web.config has this: <profile> <providers>
I have an ASP.Net-MVC app using LinqToSql. I have a subcontracts table, a service_lines
I have an asp.net mvc app, using JQuery UI dialog. I'm trying to submit
Using Unity in an ASP.Net MVC 2 app I have various dependencies on Controllers
I have an ASP.NET MVC 3 app that is using SQL Server CE 4.0

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.