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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:58:46+00:00 2026-06-08T08:58:46+00:00

view <script type=text/javascript> function getCities(abbr) { $.ajax({ url: ‘@Url.Action(SayaclariGetir, Enerji)’, data: { abbreviation: abbr

  • 0

view

<script type="text/javascript">
function getCities(abbr) {
    $.ajax({
        url: '@Url.Action("SayaclariGetir", "Enerji")',
        data: { abbreviation: abbr },
        dataType: "json",
        type: "POST",
        error: function () {
            alert("Error!");
        },
        success: function (data) {
            var items = "";
            $.each(data, function (i, item) {
                items += "<option value=\"" + item.sno + "\">" + item.seri_no + "</option>";
            });

            $("#sayaclar").html(items);
        }
    });
}

$(document).ready(function () {
    $("#musteriler").change(function () {
        var abbr = $("#musteriler").val();
        getCities(abbr);
    });
});
</script>
<div>
<table>
    <tbody>
        <tr>
            <td>@Html.DropDownListFor(x => x.musteri_id, new SelectList(Model.musteriler, "sno", "musteri_adi"), "-- Müşteri Seçiniz --", new { id = "musteriler" })
            </td>
            <td>@Html.DropDownListFor(x => x.sayac_id, new SelectList(Model.sayaclar, "sno", "seri_no"), "-- Sayaç Seçiniz --", new { id = "sayaclar" })
            </td>
            <td>
                <input type="submit" value="Kaydet" />
            </td>
        </tr>
    </tbody>
</table>
</div>

controller

[HttpPost]
public ActionResult SayaclariGetir(string abbreviation)
{
    int musteri_id = Int32.Parse(abbreviation);
    IEnumerable<TblSayaclar> _sayaclar = entity.TblSayaclar.Where(x => x.musteri_id == musteri_id);

    return new JsonResult
    {
        Data = new
        {
            success = true,
            sayaclar = _sayaclar
        },
        JsonRequestBehavior = JsonRequestBehavior.AllowGet
     };
 }

model

public class TuketimRaporViewModel
{
    public IEnumerable<TblMusteriler> musteriler { get; set; }
    public IEnumerable<TblSayaclar> sayaclar { get; set; }

    public int musteri_id { get; set; }
    public int sayac_id { get; set; }
}

When first dropdown changed I get the alert “Error!”.I cant find, Why I get alert message?

EDIT

When I write this sayaclar = new SelectList(_sayaclar,"sno","seri_no") instead of sayaclar = _sayaclar not error ocurred but,this time, second dropdownlist values are “undefined”.

Thanks.

  • 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-08T08:58:48+00:00Added an answer on June 8, 2026 at 8:58 am

    I wrote this and it works:

    [HttpPost]
    public ActionResult SayaclariGetir(string abbreviation)
    {
       int musteri_id = Int32.Parse(abbreviation);
       var _sayaclar = entity.TblSayaclar.Where(x => x.musteri_id == musteri_id).Select(x => new { sno = x.sno, seri_no = x.seri_no });
    
       return Json(_sayaclar, JsonRequestBehavior.AllowGet);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this Javascript: <script language=javascript type=text/javascript> $().ready(function() { $('#ex2').jqm({ajax: 'view.php?id=<?=$objResult[id];?>', trigger: 'a.ex2trigger'}); });
Here is fragments of my HAML view: %script{:type => text/javascript, :src => assets/application.js} :javascript
<html> <head> <script type=text/javascript> var curimage = cottage_small.jpg; var curtext = View large image;
HTML: <script src=http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js type=text/javascript></script> <script src=/js/grabber.js type=text/javascript></script> <script type=text/javascript> $(document).ready(function() { $('#search-js').submit(function() { var
The script below works as far as i can tell: <script type=text/javascript language=javascript> $(document).ready(function()
<div id="myLuckyPost"> </div> <script type="text/javascript"> function showLucky(root){ var feed = root.feed; var entries =
I want to execute this script (view source) that uses Google Translate AJAX API
I have a javascript function that works as I would like : <script language=javascript
I have a JavaScript function which redirect to Asp.net MVC action method. [AcceptVerbs(HttpVerbs.Post)] public
I'm following the tutorial here: http://www.jotorres.com/2012/01/using-jquery-and-ajax-with-codeigniter/ For my view, I have: <script type=text/javascript src=<?php

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.