0

問題 Ajax フォームで、選択した DropDownListFor の値をコントローラーに渡したいのですが、コントローラーが値を取得しない理由がわかりません。私は ASP.NET MVC を使用していますが、できる限りヘルパー関数を使用したいと考えています。

意見

@using (Ajax.BeginForm(new AjaxOptions {
HttpMethod = "Get", 
UpdateTargetId = "UserResults",
InsertionMode = System.Web.Mvc.Ajax.InsertionMode.Replace }))
{
    @Html.DropDownListFor(Model => Model.Roles, new SelectLi(ViewBag.Groups 
    as System.Collections.IEnumerable, "Value", "Text"), "Select a group",
    new { id = "Value", onchange = "$(this.form).submit();" })
}
@Html.Partial("_UsersGroup", ViewData)

コントローラ

public ActionResult test(int? selectGroup)
{

// Generate dropdownlist Groups
List<SelectListItem> groupList = new List<SelectListItem>();
var query = from s in db.Roles select s;
if (query.Count() > 0)
{
    foreach (var v in query)
    {
        groupList.Add(new SelectListItem { Text = v.Name, Value =
        v.ID.ToString() });
    }
}
ViewBag.Groups = groupList;
// End

// This part is supposed to take the passed value as parameter
if (selectGroup == null)
{
    // To do code comes here, which takes selectGroup as parameter
}

詳細

フォームは、選択に基づいた値をコントローラーに渡します。コントローラーはそれを「selectGroup」として受け取ります。

ps。初めて質問するので、間違っていたらすみません。

4

1 に答える 1