[英]ASP.Net MVC Razor Dropdownlist with submit button postback
First off, I am new to ASP.NET MVC and having a hard time finding good resources (API?) for it. 首先,我是ASP.NET MVC的新手,很难找到好的资源(API?)。 So my question comes two-fold:
所以我的问题有两个方面:
I want to try and get my dropdownlist to not auto-postback. 我想尝试让我的下拉列表不自动回发。 Instead, I'm trying to get the dropdownlist to simply select an item, and then allow a submit button to submit the GET request.
相反,我试图让下拉列表只是选择一个项目,然后允许提交按钮提交GET请求。
So if the code example I am looking at looks like this: 所以,如果我看的代码示例如下所示:
@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { id = "TheForm" })){
@Html.DropDownList(
"CategoryID",
(SelectList) ViewData["Categories"],
"--Select One--",
new{ onchange = "document.getElementById('TheForm').submit();" }
)
}
how do I alter this to instead put aa submit button to do a GET request? 如何更改此项而不是提交一个提交按钮来执行GET请求?
Secondly, anyone have any good literature that would resemble some sort of API for razor? 其次,任何人都有任何好的文献,类似于剃须刀的某种API?
You just have to add an input type='submit'
element to the form. 您只需要在表单中添加一个
input type='submit'
元素。 (And of course, change to FormMethod.Get
.) (当然,更改为
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' />
}
As far as API documentation, I think the MSDN reference is as close as you will get. 至于API文档,我认为MSDN引用尽可能接近。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.