2009-04-08 2 views
20

asp.net MVC 프레임 워크를 사용하고 있습니다. 내 페이지에는 dropdwonbox가 있고 옵션을 클릭하면 다른 페이지로 가고 싶습니다. 하지만 autopostback 속성을 true로 설정하는 방법/위치를 찾을 수 없습니다.C# asp.net mvc 사용할 때 autopostback 속성을 설정하는 방법?

영문 : 이것은 내가 사용하고 코드입니다

<%= Html.DropDownList("qchap", new SelectList((IEnumerable)ViewData["qchap"], "Id", "Title")) %> 

컨트롤러 :

public ActionResult Index(int id) 
{ 
    Chapter c = new Chapter(); 
    ViewData["qchap"] = c.GetAllChaptersByManual(id); 

    return View(); 
} 

무엇 내가 AutoPostBack을 기능을 사용하려면 어떻게해야합니까?

<%= Html.DropDownList("qchap", 
     new SelectList((IEnumerable)ViewData["qchap"], "Id", "Title"), 
     new { onchange = "this.form.submit();" }) %> 

답변

36

당신은 onchange를 클라이언트 이벤트를 사용할 수 있습니다. 아마도 양식 및 사용자 정의 html 속성을 사용하여 양식을 제출할 수 있습니다.

+0

thnx. 클래스 속성을 추가하려면이 동일한 방법을 사용해야합니까? – Martijn

+2

예, C#으로 밑줄을 붙여야합니다. 예 : new {_class = "something"} – meandmycode

+0

컨트롤러가 어떤 작업을 실행해야하는지 알 수있는 방법은 무엇입니까? –

0

DropDownList로 도우미 방법은이 기능을 지원하지 않는 것 같다

0

나는 당신이 formsCollection에 다시 게시를 조정할 수 있음도 생각

포스트 백 공공 ActionResult 지수 (FormsCollection의 myForm을)

(내가 MVC가 설치되어 내 집에있는 PC에 아니에요, 그래서 여기서 구문을 확인할 수 없음)

0

이 코드를 사용하여 해결합니다. 보기 나는 그것이 도움이되기를 바랍니다

<p> 
    <% Using Html.BeginForm()%> 
     <%=Html.DropDownList("ddlIndustry", New SelectList(CType(ViewData("IndustryList"), IEnumerable), "ID", "Name"), "--Choose industry--", New With {.onchange = "this.form.submit()"})%> 
    <% End Using %> 

    </p> 

에 대한 그런 다음 ActionResult 기능

에 대한

을 그리고

Function Index(ByVal collectionField As FormCollection) As ActionResult 

     Dim industryCategoryID As Long = collectionField.Item("ddlIndustry") 
     If industryCategoryID = 0 Then 
      Me.ViewData("IndustryList") = GlobalController.GetIndustryList 
      Return View(_service.ListCompanies()) 
     Else 
      Me.ViewData("IndustryList") = GlobalController.GetIndustryList 
      Return View(_service.ListCompanies(industryCategoryID)) 
     End If 

End Function 

. 더 완벽한 코드를 보내시겠습니까? [email protected]

관련 문제