2012-02-04 4 views
0

드롭 다운리스트에 자동 포스트 백을 수행하고 싶습니다. 보기에 내 양식 :리다이렉트 액션 ASP.NET MVC3에서 url 변경 링크

@using (Html.BeginForm("Index", "Model", FormMethod.Post)) 
{ 
      @(Html.Telerik().DropDownList() 
       .Name("ddlBrands") 
       .BindTo((IEnumerable<SelectListItem>)ViewData["brands"]) 
       .ClientEvents(events => events 
            .OnChange("onDropDownListChange") 
       ) 
      ) 
      <input type="submit" value="OK" /> 

    <table style="margin:15px; margin-left:0px;"> 
     @foreach (var item in Model) { 
      <tr> 
       <td> 
        @Html.DisplayFor(modelItem => item.FullModel) 
       </td> 
       <td> 
        @Html.ActionLink("Edit", "Edit", new { id=item.ModelID }) | 
        @Html.ActionLink("Delete", "Delete", new { id=item.ModelID }) 
       </td> 
      </tr> 
     } 
    </table> 
} 

및 자바 스크립트 :

<script type="text/javascript"> 
    function onDropDownListChange(e) { 
     SimpleAjaxRequest('/Model/Index', e.value); 
    } 

    function SimpleAjaxRequest(url, requestData) { 
     return $.ajax(
     { 
      type: 'POST', 
      url: url, 
      async: true, 
      data: { ddlBrands: requestData }, 
      dataType: "json", 
      traditional: true 
     }); 
    } 
</script> 

나는 서버에 인덱스보기에서 아약스를 통해 포스트 데이터를 전송 및 조작 데이터 후 나는 내 양식에 업데이트 데이터가 필요합니다. 내가 어떻게 할 수 있니? 나는 GET 동작

public ActionResult Index(int? ddlBrands) 
    { 
     SetBrandItems(); 
     List<Model> m = dm.GetModelsByBrandId(ddlBrands).ToList(); 
     return View(m); 
    } 

를 호출 한 후 조치를

[HttpPost] 
     public ActionResult Index(string ddlBrands) 
     { 
      SetBrandItems(); 
      return RedirectToAction("Index", "Model", new {ddlBrands = ddlBrands}); 
     } 

을 게시하려면 리디렉션하려고 해요하지만 내 페이지가 새로 고쳐지지 및 URL이 변경되지 및 데이터 업데이트되지 ... 아무도 나를 도울 수 있습니까?

+0

메신저, 당신은 페이지를 새로 고침 싶지 않아? 또는 페이지를 새로 고치시겠습니까? – Rafay

+0

메신저 내 페이지를 새로 고침하고 싶습니다. 하지만 다른 변종을 알고 내 양식에 날짜를 업데이 트하는 경우, pls 도움 – user571874

+0

당신의 GET 지수 방법은 어떻게 보이나요 – Rafay

답변

1

DropDownList 변경 이벤트는 ajax operaiton입니다. 서버 측에서 리디렉션 할 수 없다고 생각합니다. 그러나 ajax 콜백에 rediect를 추가 할 수 있습니다.

예 : 여기 혼동

function SimpleAjaxRequest(url, requestData) { 
    return $.ajax(
    { 
     type: 'POST', 
     url: url, 
     async: true, 
     data: { ddlBrands: requestData }, 
     dataType: "json", 
     traditional: true, 
     success: function() { 
      //callback redirect 
      location.href = '/Model/Index'; 
     } 
    }); 
} 

    [HttpPost] 
    public ActionResult Index(string ddlBrands) 
    { 
     SetBrandItems(); 
     return Json(null, JsonRequestBehavior.AllowGet); 
    } 
1

dropdownlist에 자동 응답을 수행하고 싶습니다. 보기에 내 양식 :

가 표준 양식의 제출 수행

function onDropDownListChange(e) { 
    $("form").submit(); 
} 

을하고 (미리 채워진 모델과) 같은보기를 반환 :

[HttpPost] 
public ActionResult Index(string ddlBrands) { 
    SetBrandItems(); 
    return View("Index", new { ddlBrands = ddlBrands }); 
} 

또는 당신이 원하는 할 AJAX를 통해 확인 하시겠습니까? 그렇다면 대신 Ajax.Form을 사용하십시오.

@using (Ajax.BeginForm(...)) { 
    ... 
}