// GET: ListDemo public ActionResult Index() { //lets use a view model here. TempListViewModel tempListViewModel = new TempListViewModel(); //lets fill this view model instance with some values. tempListViewModel = FillUpViewModelWithValues(); return(View(tempListViewModel)); }
public ActionResult Index(TempListViewModel tempListViewModel) { var selectedname = ""; selectedname = tempListViewModel.selectedName; //I am sure there are better ways to check but put a break point at this line //for Redirection Action and you will see that selectedname //holds the value that was selected in the view. return(RedirectToAction("Index")); }
private TempListViewModel FillUpViewModelWithValues() { TempListViewModel tempListViewModel = new TempListViewModel(); tempListViewModel.somevalue1 = 10; tempListViewModel.somevalue2 = 20; tempListViewModel.listOfNames = FillUpListOfNames(); //note - we are intentionally leaving the selectedName field of the view model empty return(tempListViewModel); }