【问题标题】:Why does Ajax.BeginForm return partial view in another page为什么 Ajax.BeginForm 在另一个页面中返回部分视图
【发布时间】:2015-12-26 12:58:01
【问题描述】:

我有一个视图,其中包含一个表单和一个由 Ilanlar Part 调用的局部视图。表单用于过滤局部视图数据。如果我提交表单数据以过滤局部视图数据,则操作在另一个页面中返回局部视图。如何提交表单数据并刷新部分视图数据后保持同一页面。

     *HTML*
               @using (Ajax.BeginForm("IlanlarPart", "Ilanlar", FormMethod.Post, new AjaxOptions { OnSuccess = "success" }))
 {
          <div class="panel-body">
              @Html.DropDownListFor(model => model.IlanKategoriID, new SelectList(Model.listKategoriler, "KategoriID", "KategoriAdi"), "Seçiniz", new { @class = "form-control" })
            </div>

     <div class="panel-group">
          <button type="submit" id="btnSearch">Search</button>
           </div>

 }

  public ActionResult Index()
  {
            return View((IlanInfo)getData());
  }

  public ActionResult IlanlarPart()
  {
            getData();
            return PartialView("IlanlarPart", ilanInfo);
  }

// 此操作过滤部分视图数据,但它在另一个页面中显示“Ilanlar Part”部分视图。

   [HttpPost]
    public ActionResult IlanlarPart(IlanInfo ilan)
    { 
        ilanInfo.listArsalar.Where(p => p.IlanKategoriID == ilan.IlanKategoriID).ToList();

        return  PartialView("IlanlarPart",ilanInfo);

    }

【问题讨论】:

    标签: jquery ajax asp.net-mvc asp.net-mvc-partialview


    【解决方案1】:

    我认为您想从 ajax.beginform() 获取结果。为此,您希望在视图中包含 jquery.unobtrusive-ajax.min.js 并需要启用

    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    

    在 web.config 中。 您还需要将 ajax.beginform() 更改为

    @using (Ajax.BeginForm("IlanlarPart", "Ilanlar", null, new AjaxOptions { OnSuccess = "success", HttpMethod = "Post" }))
    

    有关 ajax.beginfrom() 的更多详细信息,请点击链接http://www.niceonecode.com/Blog/DotNet/MVC/ASP_NET-MVC-Ajax_Beginform-and-Partial-View/2

    【讨论】:

    • 现在是同一页,但部分视图不显示数据,虽然应该有
    • 好的,现在在 AjaxOptions AjaxOptions { UpdateTargetId="DivContainerID",OnSuccess = "success", HttpMethod = "Post" } 中添加 UpdateTargetId 并在视图中创建一个 div 作为
      。 div 将显示部分视图结果。
    猜你喜欢
    • 2020-04-27
    • 1970-01-01
    • 1970-01-01
    • 2014-06-25
    • 2012-09-06
    • 2017-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多