21

asp.netMVCフレームワークを使用しています。私のページにはdropdwonboxがあり、オプションをクリックすると別のページに移動したいと思います。しかし、autopostbackプロパティをtrueに設定する方法/場所が見つかりません。これは私が使用しているコードです:

Aspx:

<%= 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();
}

自動ポストバック機能を使用するにはどうすればよいですか?

4

4 に答える 4

37

onchangeクライアントイベントを使用できます。

<%= Html.DropDownList("qchap", 
       new SelectList( (IEnumerable)ViewData["qchap"], "Id", "Title" ),
       new { onchange = "this.form.submit();" }) %>
于 2009-04-08T16:40:17.477 に答える
0

ポストバックをformsCollectionに調整したいと思うかもしれません

postback public ActionResult Index(FormsCollection myform)

(MVCがインストールされている自宅のPCにいないので、ここで構文を確認することはできません)

于 2009-04-09T12:15:09.040 に答える
0

このコードを使用して解決します。

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

これは ActionResult 関数用です

そして、ビューのために

 <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>

お役に立てば幸いです。より完全なコードが必要な場合は、boylevantz@gmail.comまでメールでお問い合わせください。

于 2010-01-09T13:44:45.700 に答える