@model SunChess.Model.Game
@{
ViewBag.Title = "GameList";
}
<h2>GameList</h2>
@foreach (var game in Model)
{
using (Html.BeginForm("JoinGame", "Game", FormMethod.Post))
{
<input type="hidden" name="whoJoin" value="@Context.User.Identity.Name" />
<input type="hidden" name="playedID" value="@Model.PlayerID" />
<input type="hidden" name="gameID" value="@Model.GameID" />
@Html.ActionLink("Join", "JoinGame", new { id = Model.UniqueName })
<input type="submit" value="Join Game" />
}
}
And Controller:
public ActionResult GameList()
{
List<Game> game = _gameService.GetAllNewGames();
return View(game);
}
And Yeah, error i Get is in topic name, but there are details:
Line 7: <h2>GameList</h2>
Line 8:
Line 9: @foreach (var game in (List<Game>)Model)
Line 10: {
Line 11: using (Html.BeginForm("JoinGame", "Game", FormMethod.Post))
Im using MVC3 and Entity Framework 4.
I must ask. Whats wrong. I've been doing some research trough google, but all the solutions I have found just do not work for me
using (Html.BeginForm("JoinGame", "Game", FormMethod.Post))
In addition to what others have suggested, I would suggest that you take BeginForm statement out of FOR loop since it would try to create multiple FORM tags within your markup (which, perhaps, is not what you intended).
In addition to what others have suggested, I would suggest that you take BeginForm statement out of FOR loop since it would try to create multiple FORM tags within your markup (which, perhaps, is not what you
intended).
I need multiple forms, so it's working as intended, but thanks for intrest.
iniside
Member
3 Points
11 Posts
CS1579: foreach statement cannot operate on variables of type because does not contain a public ...
Jan 12, 2011 09:09 AM|LINK
So I have something like this:
@model SunChess.Model.Game @{ ViewBag.Title = "GameList"; } <h2>GameList</h2> @foreach (var game in Model) { using (Html.BeginForm("JoinGame", "Game", FormMethod.Post)) { <input type="hidden" name="whoJoin" value="@Context.User.Identity.Name" /> <input type="hidden" name="playedID" value="@Model.PlayerID" /> <input type="hidden" name="gameID" value="@Model.GameID" /> @Html.ActionLink("Join", "JoinGame", new { id = Model.UniqueName }) <input type="submit" value="Join Game" /> } }And Controller:
public ActionResult GameList() { List<Game> game = _gameService.GetAllNewGames(); return View(game); }And Yeah, error i Get is in topic name, but there are details:
Line 7: <h2>GameList</h2> Line 8: Line 9: @foreach (var game in (List<Game>)Model) Line 10: { Line 11: using (Html.BeginForm("JoinGame", "Game", FormMethod.Post))
Im using MVC3 and Entity Framework 4.
I must ask. Whats wrong. I've been doing some research trough google,
but all the solutions I have found just do not work for me
krisrajz
Participant
1845 Points
541 Posts
Re: CS1579: foreach statement cannot operate on variables of type because does not contain a pub...
Jan 12, 2011 09:46 AM|LINK
Type of Model and game should be compatible and deterministic!
Raj
Raj
Remember to click Mark as Answer on the post that helps to others.
ignatandrei
All-Star
135087 Points
21669 Posts
Moderator
MVP
Re: CS1579: foreach statement cannot operate on variables of type because does not contain a pub...
Jan 12, 2011 09:56 AM|LINK
in addition of krisrajz
change the model from
@model SunChess.Model.Game
to
@model List<SunChess.Model.Game>
sachingusain
Star
8786 Points
1702 Posts
Re: CS1579: foreach statement cannot operate on variables of type because does not contain a pub...
Jan 12, 2011 11:06 AM|LINK
In addition to what others have suggested, I would suggest that you take BeginForm statement out of FOR loop since it would try to create multiple FORM tags within your markup (which, perhaps, is not what you intended).
Thanks.
iniside
Member
3 Points
11 Posts
Re: CS1579: foreach statement cannot operate on variables of type because does not contain a pub...
Jan 12, 2011 11:48 AM|LINK
Thanks, now it workin fine.
I need multiple forms, so it's working as intended, but thanks for intrest.