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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:39:52+00:00 2026-06-12T08:39:52+00:00

I am using MVC3 with .NET 4.0 and when my create form is invoked

  • 0

I am using MVC3 with .NET 4.0 and when my create form is invoked I get an ObjectDisposedException saying that the object has been disposed. The exception ocurrs on this MVC3 page statement:

@Html.DropDownListFor(model => model.Country, GeneralActivity.GetCountriesMVC("NL"))

And the invoked method is like this:

IEnumerable<SelectListItem> GetCountriesMVC(string preselectCountryCode)
{
   ... some error checking code omited for simplicity ...
   IEnumerable<SelectListItem> qlist;
   using (Data.MyDataContext ctx = new Data.MyDataContext()) {
      qlist = from p in ctx.Countries select new SelectListItem {
          Text = p.CountryName,
          Value = p.CountryCodeId,
          Selected = (p.CountryCodeId == preselectCountryCode)
      };
   }
   return qlist;
}

During debug I execute up to the return statement and then it leaves and brings me to the invoking @Html statement on the MVC page and the exception is thrown.

The qlist instance is declared outside the USING statement and initialized by the LINQ query so I don’t see why it says the object has been disposed.

  • 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-12T08:39:53+00:00Added an answer on June 12, 2026 at 8:39 am

    You’re not actually executing the query – so when you try to access the qList it’s attempting to connect back to your database, and the connection is closed.

    Try casting your query to a list so it will be stored in memory:

     qlist = (from p in ctx.Countries select new SelectListItem {
          Text = p.CountryName,
          Value = p.CountryCodeId,
          Selected = (p.CountryCodeId == preselectCountryCode)
      }).ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using C#.NET MVC3 (Razor) to create a simple form. But in that form
Using ASP.net MVC3 with C# I want to create a partial view that uses
Assume that: An ASP.NET MVC3 Page (using visual studio debug server) calls a WCF
I have an ASP.NET MVC3 app that features a form with a nested-table input
We are planning on using ASP.Net MVC3 to create a JSON API. For handling
I'm playing around with using ASP.NET MVC3 and have a very simple site that
Using asp.NET MVC3, I am creating trying to create an abstract class/model with the
I'm using ASP.NET MVC3 and I was wondering if there's any way to create
I'm using ASP.NET MVC3 with Razor and C#. I am making a form builder
I'm using asp.net MVC3 and enjoying the ease in which I can create client-side

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.