У меня есть следующий код:
// GET: /PlayRoundHole/Create
public ActionResult Create(int id)
{
DB db = new DB();
var t = db.Players.ToList();
IList<Player> player = db.Players.ToList();
IEnumerable<SelectListItem> selectList = from c in player
select new SelectListItem
{
Text = c.FirstName + " " + c.LastName,
Value = c.PlayerID.ToString()
};
this.ViewData["Players"] = new SelectList(selectList, "Value", "Text", "");
this.ViewData["RoundID"] = id;
return View();
}
//
// POST: /PlayRoundHole/Create
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create(FormCollection collection)
{
try
{
DB db = new DB();
PlayRound playRound = new PlayRound();
playRound.PlayerID = Int64.Parse(Request.Form["Players"]);
playRound.TenantID = 1;
playRound.RoundID = Int64.Parse(Request.Form["RoundID"].ToString());
playRound.Score = 0;
var playRoundHoles = from prh in db.PlayRoundHoles.ToList()
from hl in db.Holes.ToList()
where prh.HoleID == hl.HoleID
where prh.PlayRoundID == Int64.Parse(Request.Form["RoundID"].ToString())
select new { prh.HoleID, hl.Sequence };
foreach(var a in playRoundHoles)
{
PlayRoundHole playRoundHole = new PlayRoundHole();
playRoundHole.HoleID = a.HoleID;
playRoundHole.Stroke = Byte.Parse(Request.Form["PlayRoundHoleID_" + a.Sequence].ToString());
playRound.PlayRoundHoles.Add(playRoundHole);
}
db.SubmitChanges();
return RedirectToAction("Index");
}
catch
{
return View();
}
}
При отправке сообщения я получаю сообщение об ошибке выше.
<td><%= Html.DropDownList("Value", (IEnumerable<SelectListItem>)ViewData["Players"])%></td>
Не уверен, почему это вызвано?