简体   繁体   English

将SelectList项目列表从一个控制器传递到另一个

[英]Pass SelectList item list one controller to another

I had used select list item in controller action and pass the select list item values to another controller action by passing in parameter but didn't get any values in another controller action 我在控制器动作中使用了选择列表项,并通过传入参数将选择列表项的值传递给另一个控制器动作,但在另一个控制器动作中未获取任何值

// first controller action //第一个控制器动作

List<SelectListItem> dropdownItems = new List<SelectListItem>();
foreach (var item in (IEnumerable)singlecheckbox)
  {
    int Id = Convert.ToInt32(item);
    dropdownItems.AddRange(new[]{
    new SelectListItem() { Text = null, Value = Id.ToString() }});
  }
 return RedirectToAction("mergeletterttofiles123", "managefile", new { dropdownItems, SeatId = seatId });

// 2nd controller action //第二个控制器动作

public ActionResult mergeletterttofiles123(List<SelectListItem> dropdownItems, int SeatId, string msg)
{
     // dropdownItems shows null( 0 count)
}

As an option you can store list in Session: 您可以选择将列表存储在会话中:

...........
//your code
Session["dropdownItems"]=dropdownItems;
RedirectToAction("mergeletterttofiles123", "managefile", new { SeatId = seatId });

And then: 接着:

public ActionResult mergeletterttofiles123(int SeatId, string msg)
{
    //then get it using something like
    var dropdownItems = Session["dropdownItems"] as List<SelectListItem>;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将对象列表从一个控制器传递到另一控制器? - how to pass list of objects from one controller to another controller? 在将一个控制器传递给另一控制器时遇到问题 - Getting issue to pass one controller to another controller 从另一个列表中的列表创建选择列表 - Create selectlist from list from another list 如何从html下拉列表中获取所选项目并将其传递给mvc c#中的另一个控制器 - how to get the selected item from html dropdown list and pass it to another controller in mvc c# 如何将值从枚举选择列表传递给控制器​​以过滤结果 - How to pass value from an enum selectlist to controller to filter results 如何将值从一个 controller 传递到 .netcore 中的另一个 controller - how to pass value from one controller to another controller in .netcore 将值从一个Tabbar控制器传递到Xamarin中的另一个控制器 - Pass value from one Tabbar controller to another controller in Xamarin 如何将模型数据传递给一个控制器到另一个控制器 - How to pass model data to one controller to another controller 将列表中的视图中的特定项传递回控制器以更新数据库 - pass specific item from view in list back to controller to update database 通过ID将一个列表中的项目分配给另一个 - Assign Item from One List to Another by ID
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM