[英]C# How to set the autopostback property when using asp.net mvc?
I am using asp.net MVC framework. 我正在使用asp.net MVC框架。 On my page i have a dropdwonbox and when an option is clicked i want to go to another page.
在我的页面上我有一个dropdwonbox,当点击一个选项时,我想转到另一个页面。 But i can't find how/where to set the autopostback property to true.
但我无法找到如何/在何处将autopostback属性设置为true。 This is the code i'm using:
这是我正在使用的代码:
Aspx: ASPX:
<%= Html.DropDownList("qchap", new SelectList( (IEnumerable)ViewData["qchap"], "Id", "Title" )) %>
Controller: 控制器:
public ActionResult Index(int id)
{
Chapter c = new Chapter();
ViewData["qchap"] = c.GetAllChaptersByManual(id);
return View();
}
What do i have to do to use the autopostback functionality? 使用autopostback功能我需要做什么?
You can use the onchange client event: 您可以使用onchange客户端事件:
<%= Html.DropDownList("qchap",
new SelectList( (IEnumerable)ViewData["qchap"], "Id", "Title" ),
new { onchange = "this.form.submit();" }) %>
I solve using this code. 我解决使用此代码。
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
That's for the ActionResult function 这是ActionResult函数
And Then for the View 然后是视图
<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>
I hope it helps. 我希望它有所帮助。 I f you would like more complete codes please feel good to email me at boylevantz@gmail.com
如果您想要更完整的代码,请发送电子邮件至boylevantz@gmail.com
It seems the DropDownList helper method doesn't support this. 似乎DropDownList帮助器方法不支持这一点。 Maybe using it within a form and a custom custom html attribute to submit the form do it.
也许在表单和自定义的自定义html属性中使用它来提交表单。
I believe too that you may want to adjust your postback to the formsCollection 我也相信您可能想要将回发调整为formsCollection
postback public ActionResult Index(FormsCollection myform) 回发公共ActionResult索引(FormsCollection myform)
(I'm not on my home pc where MVC is installed, so I can't verify the syntax here) (我不在安装MVC的家用电脑上,所以我无法验证语法)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.