2013-06-01 38 views
0

我遇到了使用$ .getJSON的方法的問題。這是非常簡單的,它看起來像: 採取IDизDropDownlList的CategoryId如何返回部分從行動getJSON

<div id="partial" class="editor-label"> 
      @* @Html.Partial("");*@ 
     </div> 

    $(document).ready(function() { 
        $('#CategoryId').change(function() { 
         $.getJSON('/Publication/AjaxAction/' + this.value, {}, 
          function (html) { 
           $("#partial").html(html); 

           alert("go"); 
          }); 
        }); 
       }); 

public ActionResult AjaxAction(int Id) 
     { 
      if (Request.IsAjaxRequest()) 
      { 
       if (Id== 1) 
       { 
        ViewBag.SourceTypeId = new SelectList(db.SourceTypes, "Id", "Title"); 
        ViewBag.CityId = new SelectList(db.Cities, "Id", "Title"); 
        return Partial("_CreateStatya"); 
       } 
      } 
      return PartialView(); 
     } 

送你能告訴我如何在返回部分?

<div id="partial" class="editor-label"> 
      @* @Html.Partial("");*@ 
     </div> 
+0

$(文件)。就緒(函數(){ $( '#類別ID')。變化(函數(){$ 獲得(「@ Url.Action( 」AjaxAction「 (html); $(「#partial」)。html(html); alert(「go」);}},{id:$('#CategoryId')。val()}, 'html'); }); }); – aldangold

回答

0
$(document).ready(function() 
{ $('#CategoryId').change(function() 
{ $.get('@Url.Action("AjaxAction","Publication")', 
{id:$('#CategoryId').val()}, function (html) 
{ $("#partial").html(html); 
alert("go"); },'html'); 
}); });