我有一个下拉框,其中填充了数据库中的数据。如果我在下拉列表中选择一个项目,我想在我的控制器中使用名为 GetValueSelected() 的方法中的值。目前,我无法在 GetValueSelected 方法中获得该值。我怎样才能写这个,以便我可以获得该值并将其用于其他处理。
@model PopulateDropDownList.Models.Populate
@using PopulateDropDownList.Models
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<script src="../../Scripts/jquery-1.4.4.js" type="text/javascript"></script>
@using (Html.BeginForm("Index", "Home", FormMethod.Post, new {rnctype = "multipart/form-data" }))
{
<p>
@Html.DropDownList("mylist", Helper.GetDescription(),"--select here--")
<input id="Button1" type="button" value="button" />
</p>
}
<script language="javascript" type="text/javascript">
$(document).ready(function () {
$("#Button1").click(function () {
var SelCat = $("#mylist").val();
if (SelCat != 0) {
var url = '@Url.Action("GetValueSelected", "Home")';
$.post(url, { Id: SelCat },
function (data) {
});
}
else {
alert("You need to select an item");
}
});
});
</script>
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public void GetValueSelected()
{
string getSelectedValue = Request.Form["mylist"];
}
}