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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:25:35+00:00 2026-05-19T12:25:35+00:00

I’ve searched on SO and didn’t find any answer to the problem I’m having.

  • 0

I’ve searched on SO and didn’t find any answer to the problem I’m having.

I made a linq to get all data from two tables and one ajax call to get new data and fill my dropdownlist as the other dropdownlist changes.

Here’s what I have so far:

Controller

public ActionResult Index(int? page)
{
    vEntities db = new vEntities();

    var estados = (from e in db.estado
                   select e);

    var localidades = (from l in db.localidade
                       select l);

    ViewData["estados"] = new SelectList(estados, "cod", "descricao");
    ViewData["localidades"] = new SelectList(localidades, "id", "descricao");

    return View();
}

public ActionResult GetLocalidades(string codEstado)
{
    vEntities db = new vEntities();

    var info = (from l in db.localidade
                where l.cod_estado == codEstado
                select l);

    return Json(info);
}

View

<%= Html.DropDownList("estados", ViewData["estados"] as SelectList, String.Empty)%>
<%= Html.DropDownList("localidade", ViewData["localidades"] as SelectList, String.Empty)%>

<script type="text/javascript">
    $(document).ready(function () {
        $("#estados").change(function () {
            var ddlLocalidade = $("#localidade")[0];
            ddlLocalidade.length = 0;
            var cod = $(this).val();

            $.post(
                "/Home/GetLocalidades",
                { codEstado: cod },
                function (data) {
                    var option;
                    $.each(data, function () {
                        option = new Option(this.descricao, this.id);
                        ddlLocalidade.options.add(option);
                    });
                }
                );

        });
    });
</script>

And when I change the first dropdown, which activates the JS function, I’m getting this error right after the method “Getocalidades” returns the Json:

There is already an open DataReader
associated with this Connection which
must be closed first

I guess I’m having some trouble formatting the code 🙂 sorry for that.

I can’t see any problem with the connection, can anyone tell me what’s wrong, please ?

Thanks in advance

  • 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-19T12:25:35+00:00Added an answer on May 19, 2026 at 12:25 pm

    This is just a guess. But what happens if you change these lines

    var estados = (from e in db.estado select e);
    
    var localidades = (from l in db.localidade select l);
    
    var info = (from l in db.localidade where l.cod_estado == codEstado select l);
    

    to

    var estados = (from e in db.estado select e).ToList();
    
    var localidades = (from l in db.localidade select l).ToList();
    
    var info = (from l in db.localidade where l.cod_estado == codEstado select l).ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a text area in my form which accepts all possible characters from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
We're building an app, our first using Rails 3, and we're having to build
I have some data like this: 1 2 3 4 5 9 2 6

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.