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

  • Home
  • SEARCH
  • 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 3217124
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:22:29+00:00 2026-05-17T15:22:29+00:00

I have a MVC view that contains some dropdowns like this : <%: Html.DropDownListFor(model

  • 0

I have a MVC view that contains some dropdowns like this :

        <%: Html.DropDownListFor(model => model.CS.C1, Model.CS.Category1List, "-- Välj kategori --")%>
        <%: Html.DropDownListFor(model => model.CS.C2, Model.CS.Category2List, "-- Välj kategori --")%>
        <%: Html.DropDownListFor(model => model.CS.C3, Model.CS.Category3List, "-- Välj kategori --")%>
        <%: Html.DropDownListFor(model => model.CS.C4, Model.CS.Category4List, "-- Välj kategori --")%>
        <%: Html.DropDownListFor(model => model.CS.C5, Model.CS.Category5List, "-- Välj kategori --")%>
        <%: Html.DropDownListFor(model => model.CS.C6, Model.CS.Category6List, "-- Välj kategori --")%>

To compliment this with AJAX calls (to create CascadingDropDown) I have the following javascript :

$(document).ready(function () {

            $("#CS_C1").change(function () { lastCategoryId = $("#CS_C1").val() });
            $("#CS_C2").change(function () { lastCategoryId = $("#CS_C2").val() });
            $("#CS_C3").change(function () { lastCategoryId = $("#CS_C3").val() });
            $("#CS_C4").change(function () { lastCategoryId = $("#CS_C4").val() });
            $("#CS_C5").change(function () { lastCategoryId = $("#CS_C5").val() });
            $("#CS_C6").change(function () { lastCategoryId = $("#CS_C6").val() });

            $("#CS_C2").CascadingDropDownCategory("#CS_C1", '/AdCategory/GetCategoriesByParent', '', true, SetFilter);
            $("#CS_C3").CascadingDropDownCategory("#CS_C2", '/AdCategory/GetCategoriesByParent', '', true, SetFilter);
            $("#CS_C4").CascadingDropDownCategory("#CS_C3", '/AdCategory/GetCategoriesByParent', '', true, SetFilter);
            $("#CS_C5").CascadingDropDownCategory("#CS_C4", '/AdCategory/GetCategoriesByParent', '', true, SetFilter);
            $("#CS_C6").CascadingDropDownCategory("#CS_C5", '/AdCategory/GetCategoriesByParent', '', true, SetFilter);

            $("#LS_L2").CascadingDropDown("#LS_L1", '/Location/GetLocationsByParent', '', true);

            alert(lastCategoryId);
            SetFilter(lastCategoryId);
        });

The CascadingDropDownCategory function is from this site.

When doing a post the dropdowns is set properply but when running

SetFilter(lastCategoryId);

The lastCategoryId is sill -1? I can see that the dropdowns have got values and should also have triggered the change event? Why is i getting -1? How could I solve it?

BestRegards

  • 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-17T15:22:29+00:00Added an answer on May 17, 2026 at 3:22 pm

    lastCategoryId is set in the .change() callback (which means it won’t get set until the <select> changes), so by the end you get to the end of your document ready function it won’t be set yet.

    Also, whenever you declare a variable without var, it becomes global. Always declare variables with var at the start of a function.

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

Sidebar

Related Questions

I have an MVC view that contains a JQuery UI dialog that can be
I have an application, built using MVC, that produces a view which delivers summary
I have an ASP.NET MVC view which contains checkboxes for user-defined categories. <td><% foreach
I have an MVC application that among other things contains a small Silverlight menu
I have a view that contains a javascript function that i need to init/call
I'm trying to send a view that contains a html table as a downloadable
I have a form in an MVC view which contains a number of text
I have an MVC view with a form built with the Ajax.BeginForm() helper method,
I have a strongly-typed MVC View Control which is responsible for the UI where
I have a custom view engine in ASP.NET MVC and since upgrading to RC1

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.