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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:27:46+00:00 2026-06-06T13:27:46+00:00

Using MVC3 with NHibernate, I am having a problem with dropdowns. I have a

  • 0

Using MVC3 with NHibernate, I am having a problem with dropdowns. I have a form with various fields for user input and am only having trouble with a particular select element.

My problem is that the value of a property of the model is not shown as selected when the view loads even though the model is bound and saves properly on post. What makes this strange is that the MainPopulationFocus (code snippets below) dropdown works correctly while the MilitaryService dropdown does not.

Model – declaration of properties in question

public virtual System.Int32? MilitaryService { get; set; }
public virtual System.Int32? MainPopulationFocus { get; set; }

View – military service label and dropdown

@Html.LabelFor( m => m.MilitaryService, "Military Service" )
@Html.DropDownListFor(m => m.MilitaryService, ViewBag.MilitaryService as IQueryable<SelectListItem>, "", new { style = "width: 140px" })

HTML

<label for="MilitaryService">Military Service</label>
<select id="MilitaryService" name="MilitaryService" style="width: 140px">
    <option value=""></option>
    <option value="1028">Active</option>
    <option value="1029">Reserve</option>
    <option value="1030">National Guard</option>
    <option value="1031">Retired Military</option>
</select>

Same View – main population focus label and dropdown

@Html.LabelFor( m => m.MainPopulationFocus, "Main Population Focus" )
@Html.DropDownListFor(m => m.MainPopulationFocus, ViewBag.MainPopulationFocuses as IQueryable<SelectListItem>, "", new { style = "width: 140px" })

HTML

<label for="MainPopulationFocus">Main Population Focus</label>
<select data-val="true" data-val-number="The field MainPopulationFocus must be a number." id="MainPopulationFocus" name="MainPopulationFocus" style="width: 140px">
    <option value=""></option>
    <option value="808">Education</option>
    <option value="809">Policy</option>
    <option selected="selected" value="810">Clinical Practice</option>
    <option value="811">Research</option>
</select>

Controller – Get list of objects from service layer and save List to ViewBag

.Select(s => new SelectListItem() { Text = s.Display, Value = s.ID.ToString(), Selected = (s.ID == fellowsProfile.MilitaryService) });

The MainPopulationFocus dropdown works perfectly while the MilitaryService dropdown value chosen is bound to the model and saves in the DB but does not show the value selected when the view loads.

I know that there is an issue that exists when you use the same name for the model and dropdown but I have avoided that. I think it probably has to do with the way I formed the List.

Thanks for any possible help/suggestions.

  • 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-06T13:27:47+00:00Added an answer on June 6, 2026 at 1:27 pm

    Discovered I did use the same name and that is why I was getting my issue. Using ViewBag.MilitaryService along with the model property of MilitaryService is what broke the use of the dropdown list.

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

Sidebar

Related Questions

I am creating an ASP.NET MVC3 application using NHIBERNATE. I have a base class
I am using MVC3, EF Model first. I have a form with two DropDownList
I have an asp.net-mvc3 website using nhibernate and SQL server. I have 2 web
Using: ASP.NET MVC3 Ninject 2 Fluent nHibernate I have 2 databases (DB1 & DB2).
I have an MVC3 application using NHibernate. I've created my own membership and role
I'm using the Unity MVC3 code at http://unitymvc3.codeplex.com/ to have a NHibernate session per
I am using MVC3 and I want to have LogIn form and Register form
I have an MVC3 project using nHibernate, Rhino and Castle. I finally got all
Using MVC3, C#, and the Razor View Engine: I have a form that has
I using MVC3 and I have a form with a file upload. If the

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.