@model TestMVC4.Controllers.TestString
@{
ViewBag.Title = "Transfer";
}
@using (Html.BeginForm("redirectObject", "Collection", Model.myFriendList))
{ <h2>Transfer</h2>
@Html.ListBoxFor(s=>s.myFriendList, new SelectList(Model.myFriendList))
<button type="submit" value="test" name="btnSubmit"></button>
}
public class CollectionController : Controller
{
public ActionResult Index()
{
TestString MyListBoxFriends = new TestString();
List<string> friends = new List<string>();
friends.Add("Himanshu");
friends.Add("Sumit");
friends.Add("Jo");
friends.Add("Waan");
MyListBoxFriends.myFriendList = friends;
return View("Transfer", MyListBoxFriends);
}
[HttpPost]
public ActionResult redirectObject(TestString cc)
{
var yourFriendList = cc.myFriendList;
return View("YourView");
}
}
public class TestString
{
public List<string> myFriendList { get; set; }
}
}