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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:19:04+00:00 2026-06-01T20:19:04+00:00

I have controller var subCategories = m_listsRepository.GetSubCategories(id); var items = subCategories.Select(x=>new MyDataNameAndId(){Id = x.Value,

  • 0

I have controller

var subCategories = m_listsRepository.GetSubCategories(id);
var items = subCategories.Select(x=>new MyDataNameAndId(){Id = x.Value, Name = x.Text});
return Json(items);

And ajax:

$.ajax({
        url: urlString,
        type: 'POST',
        data: JSON.stringify({ id: districtId }),
        dataType: 'json',
        contentType: 'application/json',
        cache: 'false',
        success: function (data) {
            alert("success");
            $.each(data, function (key, MyDataNameAndId) {
                alert(key);//== 0
                alert(MyDataNameAndId);// then throws
                $('select#ChangeOnsubCategoryId').append('<option value="0">Select One</option>');

                $.each(MyDataNameAndId, function (index, manager) {
                    $('select#ChangeOnsubCategoryId').append(
                            '<option value="' + manager.Id + '">'
                            + manager.Name +
                            '</option>');
                });
            });
        }
    });

what am I doing wrong?

UPDATE:
Controller is worked.
alert(“success”); – is show
alert(key); – is show 0
alert(MyDataNameAndId); – not show.
I need generate in ‘select#ChangeOnsubCategoryId’ options from select#ChangeOnsubCategoryId

How do this? this understand?

I do not know how to show what passed json

json string:

[{"Id":"53","Name":"футбол"}]
  • 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-01T20:19:05+00:00Added an answer on June 1, 2026 at 8:19 pm

    From the JSON output you’ve written out, I’d rewrite it a little bit like this:

    $.ajax({
        url: urlString,
        type: 'POST',
        data: JSON.stringify({ id: districtId }),
        dataType: 'json',
        contentType: 'application/json',
        cache: 'false',
        success: function (data) {
            if (!data) return; // if data is empty, return
    
            var $select = $('select#ChangeOnsubCategoryId');
              // put the select element in a variable so you don't need to
              // jquery select it again
    
            $select.append('<option value="0">Select One</option>');
              // I guess you first want to add a "select one" option
    
            // data should be an array e.g. [{"Id":"53","Name":"футбол"}]
            $.each(data, function (key, manager) {
               // for each "manager" in the "data" array
    
               // manager should be an object in the data
               // array e.g. {"Id":"53","Name":"футбол"}
               // no need to for each it
    
               $select.append(
                        '<option value="' + manager.Id + '">'
                        + manager.Name +
                        '</option>');
                 // add the manager in the select box
            });
        }
    });
    

    I’m assuming stuff though. Use a javascript debugger (such as developer tools in Chrome or Firebug in Firefox) to check what values you get from the ajax call. Put the breakpoint inside the function and then watch what the data becomes (in this case it should be an array of objects containing Id and Name).

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

Sidebar

Related Questions

i have this controller: public ActionResult Novo() { var products = context.Product.Select(x => new
I have Controller: [MySite]\Controllers\DistributionTools\TrackingChannelsController.cs [HttpPost] public void InitTcFirstPageView() { var model = new TcFirstPageModel
I have a simple controller test using MvcContrib's test helpers: var controller = new
I have a list which I created in the controller: var PayList = new[]
I have this controller: public ActionResult Details(String UserName) { using (var db = new
I have the CakePHP stack in /var/www/site from one view under controller A I
I have controller with action new , and I want it to create ActiveRecord::Base
I have @Controller @RequestMapping(value=core/*) public class CoreController { public static String exceptionOccurredView = /core/exceptionOccurred;
I have the following in my controller: var $cacheAction = array( 'view/' => 432000,
Six Five Three One And I have controller: DBEntity context = new DBEntity(); //

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.