Hello, I am trying to transfer from the controller to the View, but the ViewBag in the view is always empty, what am I doing wrong? Representation
@if (item.Value is TV) { using (@Html.BeginForm("TV/" + item.Key, "Applience")) { <button type="submit" name="action" value="OnOff"><img src="~/Images/retro-tv-icon-61526.png" /></button> <br /> <button type="submit" name="action" value="show">Show</button> if ((List<string>)ViewBag.List != null) { Html.RenderPartial("TV", (List<string>)ViewBag.list); } <input type="text" name="channelTV" /> <button type="submit" name="action" value="AddChannel">Add Channel</button> <br /> <button type="submit" name="action" value="Down">-</button> <button type="submit" name="action" value="Up">+</button> <br /> <button type="submit" name="action" value="Prev"><-</button> <button type="submit" name="action" value="Next">-></button> } } Controller
public ActionResult TV(int id, string action, string channelTV) { IDictionary<int, Applience> applienceDictionary = (SortedDictionary<int, Applience>)Session["Apps"]; TV tv = applienceDictionary[id] as TV; switch (action) { case "OnOff": tv.On_Off(); break; case "AddChannel": tv.AddChannel(channelTV); break; case "Prev": tv.PrevChannel(); break; case "Next": tv.NextChannel(); break; case "Down": tv.Down(); break; case "Up": tv.Up(); break; case "show": List<string> list = tv.ShowChannels(); ViewBag.List = list; break; } return RedirectToAction("Index"); }