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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:32:09+00:00 2026-06-09T13:32:09+00:00

I need to initialize ConditionalAnalysisInput based on the selected value from the dropdown list

  • 0

I need to initialize “ConditionalAnalysisInput” based on the selected value from the dropdown list above it. I will need access to dbset in order to do that.

What would be the best way to initialize the ConditionalAnalysisInput field?

Here’s the view code:

@using (Ajax.BeginForm("_ListConditionalAnalysis",
                    new AjaxOptions { UpdateTargetId = "_conditionals",
                                      InsertionMode = InsertionMode.InsertAfter}))
{
        @Html.DropDownListFor(model=>model.AvailableConstructs,Model.AvailableConstructs)
    <p>
        <input type="submit" value="Populate" />
    </p>
}
<div id="_conditionals">
  @*** Need to init ConditionalAnalysisInput here depending on the selected value from the dropdown list. Access to dbset needed *@
   @foreach (var item in Model.ConditionalAnalysisInput)
   {
       @Html.Partial("_ListConditionalAnalysis",item)
   }
</div>
  • 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-09T13:32:10+00:00Added an answer on June 9, 2026 at 1:32 pm

    You will really want to do a callback to the server to get the new model data which you need for the next section. Initializing models (and connecting to the database) are server-side responsibilities which should never be handled directly on the client.

    I would create an action which takes the selected item and returns the list of ConditionalAnalysisInput objects which you need to deal with. Whenever the dropdownlist is changed, issue an AJAX call to get the new data and refresh your _conditionals div.

    With the normal disclaimer that this is grossly oversimplified and not something you should just past in without cleaning it up, here’s a simple example I threw together to demonstrate what I mean:

    I have two test models, which are obviously simplified. The first one would be for all of the data you need initially for the web page (i.e. the drop down list). The second model is for your partial view, which depends on the selected item from the dropdownlist:

    public class DropDownModel
    {
        public IEnumerable<string> DropDownOptions
        {
            get;
            set;
        }
    
        public DropDownModel()
        {
        }
    
        public DropDownModel(IEnumerable<string> dropDownOptions)
        {
            DropDownOptions = dropDownOptions;
        }
    }
    
    public class ConditionalsModel
    {
        public IEnumerable<string> ConditionalAnalysisInput
        {
            get;
            set;
        }
    
        public ConditionalsModel()
        {
        }
    
        public ConditionalsModel(string selectedOption)
        {
            if (selectedOption == "Option A")
            {
                ConditionalAnalysisInput = new List<string>
                {
                    "Input A 1",
                    "Input A 2",
                    "Input A 3"
                };
            }
            else if (selectedOption == "Option B")
            {
                ConditionalAnalysisInput = new List<string>
                {
                    "Input B 1",
                    "Input B 2",
                    "Input B 3"
                };
            }
        }
    }
    

    Next the controller. The main action just populates the main model and returns the view. You also need to add a second method which takes the selected item as a parameter and returns a PartialViewResult:

    public class AjaxTestController : Controller
    {
    //
    // GET: /AjaxTest/
    public ActionResult Index()
    {
    var model = new DropDownModel(new List
    {
    “Option A”,
    “Option B”
    });
    return View(model);
    }

        public PartialViewResult GetDataForDiv(string selectedOption)
        {
            var model = new ConditionalsModel(selectedOption);
            return PartialView("Conditionals", model);
        }
    }
    

    Create a “Conditionals” partial view which contains all of the markup you want to display in your _conditionals div:

    @model TestMvcProgram.Models.ConditionalsModel
    
    <ul>
    @foreach (var item in Model.ConditionalAnalysisInput)
    {
        <li>@item</li>
    }
    </ul>
    

    On your main view, add a handler for the DropDownList’s change event. During the change event, you can issue a get request to the server to invoke the GetDataForDiv method, then update the _conditionals div with the resulting partial view. Here’s my example:

    @model TestMvcProgram.Models.DropDownModel
    
    @{
        Layout = "~/Views/Shared/_Layout.cshtml";
    }
    
    <!DOCTYPE html>
    
    <html>
        <head>
            <title>title</title>
        </head>
        <body>
            <div>
                @Html.DropDownList("selectedOption", Model.DropDownOptions.Select(x => new SelectListItem { Selected = false, Text = x, Value = x }), new {id = "selectedOption"})
    
                <div id="_conditionals"></div>
            </div>
    
            <script type="text/javascript" language="javascript">
                $(function () {
                    $('#selectedOption').change(function () {
                        $.get('@Url.Action("GetDataForDiv", "AjaxTest")' + "?selectedOption=" + $(this).val(), function(data, textStatus, jqXHR) {
                            $("#_conditionals").html(data);
                        });
                    });
                });
            </script>
        </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create an enumeration that I will need to initialize from a
I'm writing a web application and need to initialize some parameters that I'm pulling
Do I need to initialize each level of a multi-level list in R? l=list()
I have WCF service that is hosted in IIS . I need to initialize
I need to initialize a session var as array. Where i do that? when
I need to initialize an object in a method without specifying the class from
I have a class that subclasses UITableViewCell. I need to initialize some of the
I'm developing a few custom ant tasks that all need to initialize the same
Where i need initialize parameter, for when form will open, to make it work?
Hi I need to initialize an NSObject at a particular location that I specify(through

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.