【问题标题】:How return Partial from Action getJSON如何从 Action getJSON 返回 Partial
【发布时间】:2013-06-01 17:00:37
【问题描述】:

我在使用 $.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 in 吗??

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

【问题讨论】:

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

标签: getjson partial


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

【讨论】:

    猜你喜欢
    • 2011-10-18
    • 1970-01-01
    • 2023-03-19
    • 2010-09-07
    • 1970-01-01
    • 2011-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多