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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:23:33+00:00 2026-06-15T12:23:33+00:00

I have two Model classes like so: Program: public class Program { public int

  • 0

I have two Model classes like so:

Program:

public class Program
{
    public int ProgramId { get; set; }

    public string Name { get; set; }

    public virtual Playlist chosenPlaylist { get; set; }

    public virtual IList<Playlist> Playlists { get; set; }
}

public class Playlist
{
    public int PlaylistId { get; set; }

    public string Name { get; set; }

    public int NumberVotes { get; set; }

    public virtual IList<Song> Songs { get; set; }
}

In my Edit Program View, I want to update the chosenPlaylist so I can allow the user to select none or one of the Program‘s Playlists.

For example:

Program 1:

  • Playlist 1
  • Playlist 2

Chosen Playlist: Playlist 1

So the user can then edit and select None (so no playlist), 1 (won’t change anything) or 2 and that gets saved to the database.

I’ve tried to create a dropdownlist in my Controller but it won’t update.

Here’s what I have in both my GET and POST Edit ActionResults:

ViewBag.chosenId = new SelectList(program.Playlists, "PlaylistId",
"Name", program.chosenPlaylist.PlaylistId);

And in my View:

@Html.DropDownList("PlaylistId", (SelectList)ViewBag.chosenId)

This displays the list fine and pre-selects the chosen Playlist, if there is one (if not, I’ll write code for it to default to the first). If there aren’t playlists in a Program, that’s easy to control.

However, problems:

  • Doesn’t update my model. If Playlist 2 is the chosen one, for example, and I choose P1, it continues to display P2 after the POST event.
  • I want to include an option in the dropdownlist for it not to pick any value (so, place a NULL in that field). Is that possible?

There are no errors thrown, everything seems to work except for the most important part – updating the database.

  • 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-15T12:23:35+00:00Added an answer on June 15, 2026 at 12:23 pm

    There’s 2 things you can do:

    Change @Html.DropDownList("PlaylistId", (SelectList)ViewBag.chosenId) into @Html.DropDownList("chosenPlaylist.PlaylistId", (SelectList)ViewBag.chosenId)

    Or use the Html.DropDownListFor(m => m.chosenPlaylist.PlaylistId, (SelectList)ViewBag.chosenId)).

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

Sidebar

Related Questions

I have a simple Fluent NHibernate model with two related classes: public class Applicant
Let's say I have the following two classes: package example.model; public class Model {
I have two classes (MVC view model) which inherits from one abstract base class.
Lets say I have two classes one base class: public class BaseModel { }
I have a simple one-to-many (models.ForeignKey) relationship between two of my model classes: class
I have two very simple classes Submission and Store class Submission(models.Model): title = models.CharField(max_length=50,
Say I have two classes: class A(db.Model): class B(db.Model): a_reference = ReferenceProperty(A) I can
I have two classes, Portfolio, and PortfolioImage. class PortfolioImage(models.Model): portfolio = models.ForeignKey('Portfolio', related_name='images') ...
I have two model classes, say parent and child. Parents are created first, and
I have two questions. 1: At the moment I have two model classes that

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.