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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:29:38+00:00 2026-06-08T01:29:38+00:00

I have this partial view rendered multiple times on a page: @model POS.Domain.Entities.Category <div

  • 0

I have this partial view rendered multiple times on a page:

@model POS.Domain.Entities.Category

<div class = "category" id= "@Model.Name">
    <h2>@Model.Name</h2>
    <a href='javascript:getView();'>Get Partial View</a>
    <script type="text/javascript">
        function getView() {
            $('#divResult').load("@Url.Action("ProductList" , "Product", new {category = Model.Name})");
        }
    </script>
    <div id="divResult">
    </div>
</div>

The idea is that when someone clicks the Get Partial View link, it will load the partial view generated by my ProductList action in my Product controller using the category value Model.Name and append that partial view to the appropriate divResult div.

The problem is that after the page has loaded, if a user clicks on any of the GetPartialView links, it loads the list of products contained within the final category and appends them to the top-most divResult div.

I am hoping for a bit of guidance in changing the script to use jQuery to appropriately load the information. I also feel that I should not be repeating the script every time this partial view is loaded. . . So how would I write the appropriate jQuery script that would do the following when the user clicks one of the Get Partial View links:

  • get the id of the parent div of the link (@ModelName)
  • use that id to make a call to my Action: @Url.Action("ProductList", "Product", new {category = **that id**})";
  • append the partial view returned by that Action to a div with the id of divResult that is within the parent div we found two steps above this step

Update

Here is the Html from my view:

<div class = "category" id= "Balls">
    <h2>Balls</h2>
    <a href='javascript:getView();'>Get Partial View</a>
    <script type="text/javascript">
        function getView() {
            var $category = $(this).closest(".category");
            var categoryName = $category.attr("id");
            //var categoryName ="Balls";
            $('.divResult').load("/Product/ProductList",
                {category: categoryName});
        }
    </script>
    <div class="divResult">
    </div>   
</div>
<div class = "category" id= "Drinks">
    <h2>Drinks</h2>
    <a href='javascript:getView();'>Get Partial View</a>
    <script type="text/javascript">
        function getView() {
            var $category = $(this).closest(".category");
            var categoryName = $category.attr("id");
            //var categoryName ="Balls";
            $('.divResult').load("/Product/ProductList",
                {category: categoryName});
        }
    </script>
    <div class="divResult">
    </div>   
</div>   

If I manually pass the value of Balls to categoryName – I can receive products from the Balls category, but if I use var categoryName = $(this).closest(".category").attr("id"); I get undefined.

Maybe seeing the HTML will help?

  • 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-08T01:29:41+00:00Added an answer on June 8, 2026 at 1:29 am

    You can use the second parameter of the load function to pass data along with the load request. Check http://api.jquery.com/load/

    Change the getView function to as follows:

    function getView(e) {
      e.preventDefault();
        var $category = $(this).closest(".category");
      var categoryName = $category.attr("id");
       $('.divResult', $category).load("@Url.Action("ProductList" , "Product")", {
         category: categoryName
        });
    }
    

    Update:
    Same ID cannot be used for multiple elements on a page. And since you are loading the partial view mutliple times and appending you would end with multiple elements having same ID. Change your partial view to as follows(use class instead of ID):

    @model POS.Domain.Entities.Category
    
    <div class = "category" id= "@Model.Name">
        <h2>@Model.Name</h2>
        <a href='/get-partial-view'>Get Partial View</a>
        <div class="divResult">
        </div>
    </div>
    

    and move the getView function to the parent view:

    <script type="text/javascript">
            function getView() {
                    var categoryName = $(this).closest(".category").attr("#id");
                    $('.divResult').load("/Product/ProductList",
                            {category: categoryName});
            }
    
            $(function(){
                $(".category").on("click", "a", getView);
            });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page that is setup like this public partial class _Default :
I have this in my partial view: <tr> <% for (int currentDay = 0;
How can i dynamically load a Partial View? I mean I have this view,
say I have this control: public partial class bloc999 : UserControl { bloc999Data mainBlock
I have a constructor question for C#. I have this class: public partial class
I have this user defined function. public partial class UserDefinedFunctions { static int i;
I have a program that looks something like this: public partial class It {
I have a view model with a list of items. These items are rendered
I have a Razor view with several fields rendered from a View model, and
I have a simple table that is rendered in an MVC partial view and

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.