Bayraktar
Bayraktar

Reputation: 41

Why does Ajax.BeginForm return partial view in another page

I have a view that contains a form and a partial view that is called by Ilanlar Part.Form is for filtering partial view data.İf I submit form data to filter partial view data,action return partial view in another page.How to stay same page after submit form data with refreshing partial view data.

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

// this action filter partial view data but it displays "Ilanlar Part" partial view in another page.

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

        return  PartialView("IlanlarPart",ilanInfo);

    }

Upvotes: 1

Views: 3631

Answers (2)

maisels
maisels

Reputation: 19

add in the Web.config: add key="UnobtrusiveJavaScriptEnabled" value="true"

Upvotes: 0

Rahul Maurya
Rahul Maurya

Reputation: 187

I think you want to ajax result from ajax.beginform(). For this you want to include jquery.unobtrusive-ajax.min.js in the view and need to enable

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

in web.config. Also you need to change ajax.beginform() as

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

For more more details how to ajax.beginfrom() works follow the link http://www.niceonecode.com/Blog/DotNet/MVC/ASP_NET-MVC-Ajax_Beginform-and-Partial-View/2

Upvotes: 5

Related Questions