我想從控制器動作傳遞字符串數組(有兩個值)到另一個另一個動作。 但是第二個動作只有這個值:'System.String []'ASP.NET MVC-無法傳遞字符串[]值到另一個控制器動作
它將值從視圖傳遞給控制器action.But當我嘗試傳遞另一個它只是傳遞空字符串。
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[]
}
如何在第一個動作中分配'標籤'變量? –
它由html上的輸入元素分配。 – balron
嘗試使用RouteValueDictionary重載而不是僅傳遞匿名對象。 –