![](/img/trans.png)
[英]I have a list of viewmodel in another viewmodel. How can I pass parameter from action to controller?
[英]Can I pass list of strings as a parameter to Controller's Action?
我想實現這樣的東西:
public ActionResult ListOfErrors(List<string> listOfErrors)
{
somelogic;
}
public ActionResult SomeAction()
{
List<string> newList = new List<string>(){"aaaa","bbbb","cccc"};
return RedirectToAction("ListOfErrors", newList);
}
但listOfErrors
在行動ListOfErrors
是1項列表與價值:System.Collections.Generic.List`1 [System.String]
可以做到嗎?
編輯:我已經根據對評論的建議更改了路由值,但在重定向操作中,我在 List 參數中得到了 null。
您可能需要 foreach 循環來迭代列表中的每個成員。 你需要這樣的東西:
foreach ( var item in newList )
{
//Your Logic
}
是的! 您可以將字符串列表作為參數傳遞給 Controller 的 Action
檢查這些鏈接:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.