如何从mvc c#中的下拉列表中获取选定的值

How to get selected value from dropdown list in mvc c#

我有一个如下所示的下拉列表。数据使用viewbag绑定。

<div class="col-md-4">
    <h2 style="color: #2f6207">dfdfDestination</h2>
    @Html.DropDownList("Destination", new SelectList(ViewBag.Destination, "regCde", "Destination", "Destination"))
</div>

现在我想将下拉列表中的选定值发送到特定控制器。我使用 jQuery 和 ajax 来执行此操作。它发送值。但是在查询值时得到空值。我不知道。还有其他方法吗?

public ActionResult MscHome(string mydestination)
{
    return View();
}

查看:

@using (Html.BeginForm("MscHome", "Home", FormMethod.Get)) 
{
    <div class="col-md-4">
        <h2 style="color: #2f6207">dfdfDestination</h2>
        @Html.DropDownList("Destination", new SelectList(ViewBag.Destination, "regCde", "Destination", "Destination"))

    </div>
    <p>
        <input type="submit" value="Submit" />
    </p>

}

控制器:

public ActionResult MscHome(string Destination)
{
    return View();
}

请注意,您必须在 Html.BeginForm 上指定操作和控制器,以便视图知道在何处执行 HttpGet 或 HttpPost,并且下拉列表值的名称应等于操作的参数名称结果在控制器中。