Ajax populating dropdown for c# results in undefined

I only get the text message Selektoni Tipin, but I dont get any values from the tables I only get undefined

AJAX script

script type="text/javascript">     $(document).ready(function () {         $.ajax({             type: "GET",             url: "/Dokument/Dokument",             data: "{}",             success: function (data) {                 var s = '<option value="-1">Selektoni Tipin</option>';                 for (var i = 0; i < data.length; i++) {                     s += '<option value="' + data[i].Id_Tipi + '">' + data[i].Emri_llojit + '</option>';                 }                 $("#tipiDropdown").html(s);             }         });     }); </script> 

Controller method

 public ActionResult Dokument()         {              return View();         }         // GET: NgarkoDokument           public ActionResult GetTipi(int tipiId)         {             Test_kristiEntities db = new Test_kristiEntities();             return Json(db.Tipi.Select(x => new             {                 Id_Tipi = x.Id_Tipi,                 Emri_llojit = x.Emri_llojit             }).ToList(), JsonRequestBehavior.AllowGet);             // return View();         } 

Model i built with some tables

public class NgarkoDokument     {         public Dokumenti Dokumenti { get; set; }         public Fusha_Indeksimit FushaIndeksimit { get; set; }         public Vendndodhja_Fizike Vendndodhja_fizike { get; set; }         public Tipi Tipi { get; set; }               } 

And here is the html

<select title="Lloji i dokumentit" name="lloji" class="form-control col-md-3 box" id="tipiDropdown"> </select> 
Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.