Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 28th, 2012  |  syntax: None  |  size: 1.95 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Json result is nothing
  2. $(function () {
  3.         $('#UserGaleries_').change(function () {
  4.             try {
  5.  
  6.                 if ($(this).val() == -1) {
  7.  
  8.                     $('#NameGaleriesEdit').val('');
  9.                     $('#DescriptionGaleriesEdit').val('');
  10.  
  11.                 }
  12.                 else {
  13.                     $.post('/UserGaleries/ChangeCategorie',
  14.                         { selectedID: $(this).val() },
  15.                         function (data) {
  16.                             alert(data.Name); //Nothing
  17.                             $('#NameGaleriesEdit').val(data.name);
  18.                             $('#DescriptionGaleriesEdit').val('asdf');
  19.  
  20.                         });
  21.                 }
  22.             } catch (e) {
  23.                 alert(e);
  24.             }
  25.  
  26.         });
  27.     });
  28.        
  29. [Serializable]
  30. public class ResponsetModel
  31. {
  32.     public int Id { get; set; }
  33.     public string Description { get; set; }
  34.     public string Name { get; set; }
  35. }
  36.  
  37. public JsonResult ChangeCategorie(int selectedID)
  38. {
  39.     DbLayer.UserGaleriesManager uc = new DbLayer.UserGaleriesManager();
  40.     DbLayer.Models.UsersGalery cat = uc.GetGaleriesById(selectedID);
  41.  
  42.     ResponsetModel retValue = new ResponsetModel()
  43.     { Id = cat.Id, Name = cat.Title, Description = cat.Description };
  44.  
  45.     JsonResult oView = Json(retValue, "text/plain", System.Text.Encoding.UTF8, JsonRequestBehavior.AllowGet);
  46.     return oView;
  47. }
  48.        
  49. $.ajax({
  50.     url:'/UserGaleries/ChangeCategorie',
  51.     data:{ selectedID: $(this).val() },
  52.     method:"POST",
  53.     dataType:"json",
  54.     success:function (data) {
  55.         alert(data.Name);
  56.     }
  57. });
  58.        
  59. $.post('/UserGaleries/ChangeCategorie',
  60.               { selectedID: $(this).val() },
  61.               function (data) {
  62.                             alert(data.Name);
  63.                             $('#NameGaleriesEdit').val(data.Name);
  64.                             $('#DescriptionGaleriesEdit').val('asdf');
  65.  
  66.               }, "json");