Click here to Skip to main content
15,741,892 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Can some one help me to find this...
jo.him1988 9-Jul-14 4:25am    
Hi, here is an example of transfering data from view to controller
i have made a model class TestString which have a property of list<string>myFriendList
i am using this collection string to bind with listbox and sending this details to controller here is the code

1 solution

@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
        // GET: /Collection/

        public ActionResult Index()
            TestString MyListBoxFriends = new TestString();
            List<string> friends = new List<string>();
            MyListBoxFriends.myFriendList = friends;
            return View("Transfer", MyListBoxFriends);
        public ActionResult redirectObject(TestString cc)
            var yourFriendList = cc.myFriendList;
            return View("YourView");
//this is model class which is bind to view
    public class TestString
        public List<string> myFriendList { get; set; }
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900