【发布时间】:2014-04-22 11:37:04
【问题描述】:
我正在尝试将字符串数组(具有两个值)从控制器动作传递到另一个动作。 但第二个动作只有这个值:'System.String[]'
它将值从视图传递到控制器动作。但是当我尝试传递另一个时它只是传递空字符串。
Html(剃刀)
@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>
控制器:
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[]
}
【问题讨论】:
-
如何在第一个操作中分配
tags变量? -
它由html上的输入元素分配。
-
尝试使用 RouteValueDictionary 重载,而不是只传递一个匿名对象。
标签: c# asp.net-mvc asp.net-mvc-4 razor