简体   繁体   English

C#如何在使用asp.net mvc时设置autopostback属性?

[英]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.

相关问题 在ASP.NET C#中使用自动邮寄问题 - Problem in using AutoPostback in asp.net c# ASP.NET MVC C#设置模型属性值 - ASP.NET MVC C# set model property values 将C#ASP.NET MVC 3 SQL数据库转换为html.dropdownlistfor和AutoPostBack to Browse操作 - C# ASP.NET MVC 3 SQL database to html.dropdownlistfor and AutoPostBack to Browse action on selecting and item 在自动回发ASP.net C#之后将重点放在下一个文本框/ tabindex - Set focus on next textbox/tabindex after autopostback ASP.net C# 当RadioButtonList选择asp.net C#时,SelectedIndexChanged无法正常工作? autopostback还设置为true吗? - SelectedIndexChanged not working while RadioButtonList selected asp.net c#? autopostback also set to true? 如何在ASP.NET中以C#作为代码,以编程方式设置(使用GET SET属性)“ httpRuntime maxRequestLength” - How to programmatically set (using GET SET property) “httpRuntime maxRequestLength” in ASP.NET with C# as code behind 如何在ASP.NET C#中向按钮动态添加AutoPostBack = true - How to dynamically add AutoPostBack = true to button in ASP.NET C# 如何在MVC3中使用@Viewbag在ASP.NET C#中将值设置为@ Html.TextBox() - How to set value to @Html.TextBox() in ASP.NET C# using @Viewbag in MVC3 如何使用C#在ASP.NET MVC中下载文件? - How to download a file in ASP.NET MVC using C#? C#/ ASP.NET MVC:我设置了属性的值,但它仍然为null - C#/ASP.NET MVC: I set the property's value, but it's still null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM