我正在尝试将字符串数组(有两个值)从一个 Controller 操作传递到另一个操作。 但第二个 Action 只有这个值:'System.String[]'
它将值从 View 传递到 Controller 操作。但是当我尝试传递另一个值时,它只传递空字符串。
Html( Razor )
@using (Html.BeginForm("AnnouncementCreate", "Administrator", FormMethod.Post, new { id = "form" }))
{
//There are another html elements....
<label class="checkbox-inline">
<input type="checkbox" name="tags" id="web" value="web" checked="checked" />
<span>Web</span>
</label>
<label class="checkbox-inline ">
<input type="checkbox" name="tags" id="ambulance" value="client" checked="checked" />
<span>Ambulance Client</span>
</label>
Controller :
public ActionResult AnnouncementCreate(NewsItem NEWS, Guid RSSCATEGORY,Guid NEWSIMAGETYPE,string[] tags)
//tags variable have two values: [0]:web , [1]:client
{
....
//I want to Pass current string[] values to another Action
return RedirectToAction(actionName: "Announcements", routeValues: new { tags = tags });
}
//2nd action method
public ActionResult Announcements(string[] tags)
{
//tags variable has this value: [0]: System.String[]
}
最佳答案
我认为最好使用 TempData,如下所示:
public ActionResult AnnouncementCreate(NewsItem NEWS, Guid RSSCATEGORY,Guid NEWSIMAGETYPE,string[] tags)
//tags variable have two values: [0]:web , [1]:client
{
....
TempData["tags"] = tags;
return RedirectToAction(actionName: "Announcements");
}
//2nd action method
public ActionResult Announcements()
{
var tags = (string[]) TempData["tags"];
}
祝你好运!
关于c# - ASP.NET MVC - 无法将 string[] 值传递给另一个 Controller 操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23218363/