繁体   English   中英

带有提交按钮回发的ASP.Net MVC Razor Dropdownlist

[英]ASP.Net MVC Razor Dropdownlist with submit button postback

首先,我是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?

您只需要在表单中添加一个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引用尽可能接近。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM