C#使用asp.net mvc时如何设置autopostback属性?
我正在使用asp.NETMVC框架。在我的页面上,我有一个dropdwonbox,当单击一个选项时,我想转到另一个页面。但是我找不到如何/在何处将autopostback属性设置为true。这是我正在使用的代码: Aspx:C#使用asp.net mvc时如何设置autopostback属性?,c#,asp.net-mvc,combobox,autopostback,C#,Asp.net Mvc,Combobox,Autopostback,我正在使用asp.NETMVC框架。在我的页面上,我有一个dropdwonbox,当单击一个选项时,我想转到另一个页面。但是我找不到如何/在何处将autopostback属性设置为true。这是我正在使用的代码: Aspx: 要使用自动回邮功能,我必须做些什么?您可以使用onchange客户端事件: <%= Html.DropDownList("qchap", new SelectList( (IEnumerable)ViewData["qchap"], "Id", "Ti
要使用自动回邮功能,我必须做些什么?您可以使用onchange客户端事件:
<%= Html.DropDownList("qchap",
new SelectList( (IEnumerable)ViewData["qchap"], "Id", "Title" ),
new { onchange = "this.form.submit();" }) %>
DropDownList助手方法似乎不支持此功能。
也许在表单中使用它和自定义html属性来提交表单就可以了。我也认为您可能需要调整回发到formsCollection 回发公共操作结果索引(FormsCollection myform)
(我不在安装了MVC的家用电脑上,因此无法验证此处的语法)我使用此代码进行求解
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>
我希望有帮助。如果您想要更完整的代码,请发送电子邮件至thnx。如果我想添加class属性,我必须使用同样的方式吗?是的,尽管使用c#时,你需要用下划线作为前缀。。ie new{{u class=“something”}控制器如何知道需要执行哪些操作?
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
<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>