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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:04:29+00:00 2026-06-06T01:04:29+00:00

I have a DropDownList that contains Station codes. @Html.DropDownList(Station, null, new { id =

  • 0

I have a DropDownList that contains “Station” codes.

@Html.DropDownList("Station", null, new { id = "dd_custom"});

The DropDownList is filled by ViewData["Station"] (list of SelectListItem).

My goal is simple: when the DropDownList CHANGES (In bold, because I know onchange exists, but cannot make it work.), I want the @ViewBag.CurrentStation to be equal to the station chosen.

What I’ve tried:

  1. Javascript via this website, this website, and many other websites.
  2. Ajax

Still, I can’t figure out how to make this dropdownlist to interact with my Controller (base Controller from the MVC4 template (Internet Application)).

The easiest way would be to interact from my index.cshtml to HomeController.cs, but I can’t figure out how.

Can someone help ?

Thanks


Edit: I need the Station Code for all my pages. The User can only modify the Station on the Home page, but I need the Station on the other page to produce reports. Global Variable would be the answer maybe, like using Application[“VarName”], but still, don’t know how to interact with my DropDownList => C# Class.

  • 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-06T01:04:31+00:00Added an answer on June 6, 2026 at 1:04 am

    The data you store in the ViewData, ViewBag will exists for only one request. Say for ex. when the dropdown changes if you are making a request to server and set the new value to @ViewBag.CurrentStation but that won’t be available for the next request because it’s gone.

    If you want to call some controller action when the dropdown changes you could do that through ajax using jquery.

    To submit the selected value of dropdown to server you can refer this thread.

    If you want the current station to be persisted for more than one request for an user then you can use session.

    Server-Side

    public class StationController: Controller
    {
       public ActionResult SaveCurrentStation(int stationId)
       {
           Session["CurrentStation"] = stationId;
    
           return new EmptyResult();
       }
    }
    

    Client-Side

    $("#dropdownId").change(function(){
       var selStationId = $(this).val();
       $.post("/Station/SaveCurrentStation", {stationId: selStationId });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have the following view that contains an @Html.DropDownList :- <fieldset> <legend>Answer here</legend> <div
I have dropdownlist that is dynamically created and contains a list of users. If
i have a dropdownlist that populates from the sql server database. populating the list
I have a webpage written in HTML. I have a dropdown list that is
I have a DropDownList called (DDL) in ASP.net page, I want that DDL contains
I have a HTML page that contains a search box containing a number of
I have a table that contains a list of EquipmentIDs and another table that
I have the following code in a custom user control that contains a DropDownList
I have a page that contains dynamically generated Dropdown List controls and I want
I have an ASP.NET dropdownlist called #ddlDateRange that contains several items. Possible values in

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.