【问题标题】:pass dropdown list value to controler in Asp.net MVC将下拉列表值传递给 Asp.net MVC 中的控制器
【发布时间】:2013-12-31 07:06:34
【问题描述】:

这里在视图中声明一个下拉列表

<div class="input-group">
<label class="sectionHeaderStyle" for="UserName">Select Domain</label>                   
@Html.DropDownList("DomainName", (SelectList)ViewBag.applicationList,"Select", new        {@onchange = "javascript:sendParam();" })                                         
</div>

这里是调用javascript函数

<script type="text/javascript">
function sendParam()
{
window.location = "GetGroupsListPost?id=" + jQuery("#DomainName").val();
}
</script> 

这是我生成视图的操作结果

public ActionResult ManageGroups()
{
List<string> lsForest = new List<string>();
using (var forest = Forest.GetCurrentForest())
{
foreach (Domain d in forest.Domains)
{
lsForest.Add(d.Name);
}
}
var DomainList = from c in lsForest select c;
ViewData["DomainName"] = new SelectList(DomainList);
return View();
}

我想在另一个 actionresult 中读取选定的值,即

public ActionResult GetGroupsList(string strdomain)
{           
}

【问题讨论】:

    标签: jquery asp.net-mvc jqgrid


    【解决方案1】:

    因为你的控制器 Action 是

    public ActionResult GetGroupsList(string strdomain)
    {           
    }
    

    使用,你需要传递strdomain作为查询字符串参数而不是id

    function sendParam()
    {
       window.location.href = "GetGroupsListPost?strdomain=" + jQuery("#DomainName").val();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多