mercredi 21 janvier 2015

C# MVC Html.CheckBoxFor not binding to model

I'm having a frustrating issue where I can't seem to get the Model binding to work with CheckBoxFor when posting back to the controller. My model just returns back null. Any help would be appreciated!


View



@model IEnumerable<FFR.Context.Matchup>

@{
Layout = null;
}

<!DOCTYPE html>

<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>View1</title>
</head>
<body>
<p>
@Html.ActionLink("Create New", "Create")
</p>
@using (Html.BeginForm(Html.BeginForm("Submit", "Matchups", FormMethod.Post)))
{
@foreach (var item in Model) {
<tr>
<td>@Html.CheckBoxFor(modelItem => item.isChecked)</td>

<td>
@Html.DisplayFor(modelItem => item.MatchupDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.Spread)
</td>
<td>
@Html.DisplayFor(modelItem => item.HomeScore)
</td>
<td>
@Html.DisplayFor(modelItem => item.AwayScore)
</td>
}

<tr><td><input type="submit" value="Submit" /></td></tr>

</table>
}
</body>
</html>


Controller



[HttpPost]
public ActionResult Submit(IEnumerable<Matchup> model)
{

//processing

}


Model



public partial class Matchup
{
public Matchup()
{
this.Bets = new HashSet<Bet>();
}

public int MatchupId { get; set; }
public int HomeTeamId { get; set; }
public int AwayTeamId { get; set; }
public int LocationId { get; set; }
public System.DateTime MatchupDate { get; set; }
public int WeekId { get; set; }
public int SeasonId { get; set; }
public Nullable<decimal> Spread { get; set; }
public Nullable<decimal> HomeScore { get; set; }
public Nullable<decimal> AwayScore { get; set; }
public string TimeLeft { get; set; }
public Nullable<System.DateTime> LastUpdate { get; set; }
public Boolean isChecked { get; set; }
}




Aucun commentaire:

Enregistrer un commentaire