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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:27:05+00:00 2026-05-15T17:27:05+00:00

Long story short, I’m trying to add a few extra items to ViewData to

  • 0

Long story short, I’m trying to add a few extra items to ViewData to make my life easier, and its an edge case that doesn’t really justify its own model just for this one case. Keep reading for more specific details.

So I have a strongly typed edit view for one of my objects, everything works great until I try to put a dropdownlist on the view with an ID that does not match a property of my class.

I have this

public class MyModel
{
    public String Name {get;set;}
    public int ID {get;set;}
    public MyOtherModel Other {get;set;}
}
public class MyOtherModel
{
    public String Name {get;set;}
    public int ID {get;set;}
}

I am able to update the Name property.

I’d also like to set the Other.ID property from a DropDownList, but its not letting me do that.

My Controller looks like this

public ActionResult EditView()
{
    var da = new DataAccessClass();
    var Names = da.ReadActive(); // returns MyOtherModel
    var sli = new SelectList(evNames, "ID", "Name");
    ViewData["OtherModelNames"] = sli;
    return View();
}

My View looks like this:

<p>
    <label for="EndTime">Name:</label>
    <%= Html.TextBox("Name") %>
    <%= Html.ValidationMessage("Name", "*")%>
</p>
<p>
    <label for="EndTime">Other Name:</label>
    <%= Html.DropDownList("OtherNameIDList", (SelectList)ViewData["OtherModelNames"]) %>
    <%= Html.ValidationMessage("OtherNameIDList", "*")%>
</p>

I get an error on this line <%= Html.DropDownList("OtherNameIDList", (SelectList)ViewData["Names"]) %>

“There is no ViewData item with the key ‘OtherNameIDList’ of type ‘IEnumerable’.”

My expectation is that in the controller action that accepts the POST, I will manually use the FormCollection[] to read out that ID and populate MyOtherModel with the correct ID.

  • 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-15T17:27:06+00:00Added an answer on May 15, 2026 at 5:27 pm

    In the controller try:

    public ActionResult EditView()
    {
        var da = new DataAccessClass();
        var Names = da.ReadActive(); // returns MyOtherModel
        var sli = new SelectList(evNames, "ID", "Name");
        ViewData.Add("OtherModelNames", new SelectList("ID", "Name", ""));
        return View();
    }
    

    The in the view

    Html.DropDownList("OtherModelNames")
    

    To get the Other.Id in the dropdownlist, just create a static int in the class:

    public static int OtherId {get { return this.Other.Id; }}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So long story short, im trying to build a chat application....well its already built
Long story short, I have an ASP.NET application I'm trying to debug and at
Long story short, I want to add an absolutely positioned pseudo element after another
Long story short I am trying to replicate the Sleeping barber problem in Erlang.
Long story short, here's what i'm going to be trying to do: There is
To cut a long story short I am attempting to add some functionality to
To make a long story short I have to use processing in a class
I'm trying to create a simple animation. Long story short, I've got a list
Long story short - In order to make something work correctly, I need to
Long story short, we found files promoting prescription drugs on our server that we

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.