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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:03:42+00:00 2026-06-17T09:03:42+00:00

I have a ViewModel into my application like this: public class ItemViewModel { public

  • 0

I have a ViewModel into my application like this:

public class ItemViewModel {
    public string Name { get; set; }

    public string SelectedType { get; set; }
    public IEnumerable<Type> Types { get; set; }

    public string SelectedSubtype { get; set; }
    public IEnumerable<Subtype> Subtypes { get; set; }
}

I’ve created a View to exposes these properties:

@Html.TextBoxFor(m => m.Name)

@Html.DropDownListFor(m => m.SelectedType,
    new SelectList(Model.Types, "ID", "Description"),
    "Select a type")

@Html.DropDownListFor(m => m.SelectedSubtype,
    new SelectList(Model.Subtypes, "ID", "Description"),
    "Select a subtype")

Well, when I want to refresh my subtypes dropdownlist, I have to write a lot of DOM code to generate the new options.

$('#SelectedType').change(function() {
    $.get('/json/GetSubtypesFromType', { 'type': $(this).val() }, function(result) {

        var options = '';
        for (var count = 0; count < result.length; count++) {
            options += "<option value='" + result[count].ID + "'>" + result[count].Description + "</option>";
        }

        $('#SelectedSubtype').html(options);
    });
});

Is there a way to bind the new options to Subtypes enumerable into my ViewModel instead write this code for generate the options. I need to retrieve the new enumerable when I post my form, but I want to bind the new values into ViewModel collection.

  • 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-17T09:03:43+00:00Added an answer on June 17, 2026 at 9:03 am

    Observation: You are ‘get’-ting values with AJAX and want the new values added to your DropDownList Helper.

    Suggestion1: Create a custom Ajax Drop Down List Helper.

    read this article on http://www.codeproject.com/Articles/421640/Creating-a-custom-AJAX-Helper

    another good ref How to make the equivalent of @Ajax.DropDownList?

    particularly valuable ref
    http://www.mikeyd.com.au/2009/08/22/dynamically-populate-a-selectdrop-down-list-using-aspnet-mvc-jquery-and-json/

    Suggestion 2: Use an action partial to create your dropdownlist
    Executed as @Html.Action("{Action}", {Controller}", new { id = {param})

    or from jquery as $('#dropdowndiv').load('/{Controller}/{Action}'), action partials first call an action method, then render a partial view. This is ideal for cases where you want to dynamically create a selectlist on the fly

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

Sidebar

Related Questions

I have this ViewModel public class CustomerSuscribeViewModel : IValidatableObject { [DataMember(IsRequired = true)] [DataType(DataType.Text)]
We have a ViewModel with a collection of Widget<dynamic> : public class Widget<T> {
I am developing an ASP.Net MVC 3 web application. I have a ViewModel public
I have a user control let say UC1 . This user control have viewmodel
I have a viewmodel which is subscribing to the event NavigationCompletedEvent. This viewmodel need
I have a ViewModel class that contains a list of points, and I am
I have a ViewModel which exposes the string property PageToolBarVisible which can be true
This is the situation: I have an ASP.NET MVC 4 application. When I run
I'm trying to pass my View an instance of the following ViewModel: public class
I have done some research into this, but I am not particularly experienced with

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.