C#如何在使用asp.net mvc时设置autopostback属性?
我正在使用asp.net MVC框架。 在我的页面上我有一个dropdwonbox,当点击一个选项时,我想转到另一个页面。 但我找不到如何/在哪里将autopostback属性设置为true。 这是我正在使用的代码:
ASPX:
控制器:
public ActionResult Index(int id) { Chapter c = new Chapter(); ViewData["qchap"] = c.GetAllChaptersByManual(id); return View(); }
我需要做什么才能使用自动回复function?
您可以使用onchange客户端事件:
<%= Html.DropDownList("qchap", new SelectList( (IEnumerable)ViewData["qchap"], "Id", "Title" ), new { onchange = "this.form.submit();" }) %>
似乎DropDownList帮助器方法不支持这一点。 也许在表单和自定义自定义html属性中使用它来提交表单。
我也相信您可能希望将回发调整为formsCollection
回发公共ActionResult索引(FormsCollection myform)
(我不在安装MVC的家用电脑上,所以我无法validation语法)
我解决使用此代码。
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函数
然后是视图
<% Using Html.BeginForm()%> <%=Html.DropDownList("ddlIndustry", New SelectList(CType(ViewData("IndustryList"), IEnumerable), "ID", "Name"), "--Choose industry--", New With {.onchange = "this.form.submit()"})%> <% End Using %>
我希望它有所帮助。 如果您想要更完整的代码,请发送电子邮件至boylevantz@gmail.com