如何从Action getJSON返回Partial

时间:2013-06-01 17:00:38

标签: getjson partial

我遇到使用$ .getJSON的方法有问题。它非常简单,看起来像这样: 拿ID和DropDownlList CategoryId

   <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();
        }

你能告诉我如何返回Partial吗?

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

1 个答案:

答案 0 :(得分:0)

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