【问题标题】:ASP.Net MVC Razor Dropdownlist with submit button postback带有提交按钮回发的 ASP.Net MVC Razor 下拉列表
【发布时间】:2013-12-17 07:54:04
【问题描述】:

首先,我是 ASP.NET MVC 的新手,很难为它找到好的资源(API?)。所以我的问题有两个方面:

我想尝试让我的下拉列表不自动回发。相反,我试图让下拉列表简单地选择一个项目,然后允许提交按钮提交 GET 请求。

因此,如果我正在查看的代码示例如下所示:

 @using (Html.BeginForm("Index", "Home", FormMethod.Post, new { id = "TheForm" })){
     @Html.DropDownList(
         "CategoryID", 
         (SelectList) ViewData["Categories"], 
         "--Select One--", 
         new{ onchange = "document.getElementById('TheForm').submit();" }
     ) 
 }

如何更改此设置以放置一个提交按钮来执行 GET 请求?

其次,任何人都有任何类似于剃须刀 API 的优秀文献吗?

【问题讨论】:

    标签: c# asp.net-mvc razor


    【解决方案1】:

    您只需在表单中添加一个input type='submit' 元素。 (当然,更改为FormMethod.Get。)

    @using (Html.BeginForm("Index", "Home", FormMethod.Get, new { id = "TheForm" })) 
    {
        @Html.DropDownList( "CategoryID", 
            (SelectList) ViewData["Categories"], 
            "--Select One--", 
            new{ onchange = "document.getElementById('TheForm').submit();" }
        ) 
    
        <input type='submit' value='Submit' />
    }
    

    就 API 文档而言,我认为 MSDN reference 与您将获得的一样接近。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-25
      • 1970-01-01
      相关资源
      最近更新 更多