public ActionResult SetChannel(int id, string channel) { IDictionary <int, Device> devicesDictionary = (SortedDictionary <int, Device>)Session["Devices"]; ISetChannel c = (ISetChannel)devicesDictionary[id]; int currentChan; if (Int32.TryParse(channel, out currentChan)) { if (currentChan >= 0 && currentChan <= 100) { c.SetChannel(currentChan); } else { TempData["Error"] = "Введите значение от 0 до 100!"; } } else { TempData["Error"] = "Введите только цифры!"; } Session["Devices"] = devicesDictionary; return(RedirectToAction("Index")); }