コントローラーの httpGet でドロップダウンリストを作成しました。今度は、HttpPost メソッドで選択した dropdownlsit の値を、さらに操作を実行するための文字列として取得します。私の場合、get メソッドでロールのドロップダウンリストを作成し、その選択したロールを削除したいhttpPostメソッドで。どうすればできますか??どんな助けでも大歓迎です。ここに私のコードがあります。
[HttpGet]
public ActionResult DeleteRole(RoleManager role)
{
string[] allRoles = ((CustomRoleProvider)Roles.Provider).GetAllRoles(role);
var roleModel = new RoleManager
{
AllRoles = allRoles.Select(x => new SelectListItem() { Text = x, Value = x })
};
return View(roleModel);
}
意見:
@Html.DropDownListFor( m => m.AllRoles,new SelectList (Model.AllRoles,"Text","Value"))
[HttpPost]
public ActionResult DeleteRole()
{
//get selected value of dropdownlist in a string??
}