2014-07-07 5 views
0

MVC Ajax 양식을 가지고 있습니다. 드롭 다운 목록에서 항목을 변경하여 컨트롤러에 Ajax 요청을 보내려고합니다. 나는 아래 코드를 시도했지만, 내 컨트롤러는 Ajax 요청이 아닌 정상적인 요청을 처리했다.MVC Ajax 양식이 드롭 다운 목록과 작동하지 않습니다. 항목 변경 이벤트?

보기 :

@using (Ajax.BeginForm("CashReceipt", "Admin",null, new AjaxOptions { HttpMethod = "POST", InsertionMode = InsertionMode.Replace, UpdateTargetId = "updateContainer" }, new { @class = "smart-form",@id="ajaxform" })) 
{ 
List<SelectListItem> sli = new List<SelectListItem>() 
{ 
new SelectListItem { Text = "Paid", Value = "Paid" }, 
new SelectListItem { Text = "Unpaid", Value = "Unpaid" 
} }; 
<label class="select"> 
@Html.DropDownList("Filter", new SelectList(sli, "Text", "Value", ViewBag.Filter), "--", new { @onchange = "this.form.submit();" }) 
<i></i> 
</label> 
} 

컨트롤러 :

[HttpPost] 
    public ActionResult CashReceipt(string Filter="") 
    { 
     if (Request.IsAjaxRequest()) 
     { 
      return PartialView("_CashReceipt", model); 
     } 
     return View(model); 
    } 

Ajax 요청이 버튼을 클릭 이벤트와 컨트롤러에서 식별하지만 변화에 대한 드롭 다운 목록입니다. 왜? 드롭 다운 목록 항목 변경으로이 작업을 수행 할 수있는 방법을 제공해주십시오.

누구든지이 문제에 관해 도움을 줄 수 있습니까?

@using (Ajax.BeginForm("CashReceipt", "Admin",null, new AjaxOptions { HttpMethod = "POST", InsertionMode = InsertionMode.Replace, UpdateTargetId = "updateContainer" }, new { @class = "smart-form",@id="ajaxform" })) 
{ 
List<SelectListItem> sli = new List<SelectListItem>() 
{ 
new SelectListItem { Text = "Paid", Value = "Paid" }, 
new SelectListItem { Text = "Unpaid", Value = "Unpaid" 
} }; 

<button type="submit">Submit</button> 

<label class="select"> 
@Html.DropDownList("Filter", new SelectList(sli, "Text", "Value", ViewBag.Filter), "--", ) 
/* Here I removed new { @onchange = "this.form.submit();" } */ 
<i></i> 
</label> 
} 

컨트롤러 :

[HttpPost] 
    public ActionResult CashReceipt(string Filter="") 
    { 
     if (Request.IsAjaxRequest()) 
     { 
      return PartialView("_CashReceipt", model); 
     } 
     return View(model); 
    } 

답변

0

이 나를 위해 일했다. 누군가에게 도움이 될 수 있습니다.

new { onchange = "$(this.form).submit();" } 
관련 문제