Wonder if someone could point me in the right direction please?
Basically I'm trying to create a page to allow someone to enter data (golf) on a number (18) of holes and basically I'm unsure of how it's done.
In the model I've created the following:
namespace BGSociety.Models
{
public class CreateCourseHolesViewModel
{
public int holeNumber { get; set; }
public int par { get; set; }
public int si { get; set; }
public int distance { get; set; }
}
}
In the Index event of the controller I've got:
TempData["holes"] = getHoles();
protected List<CreateCourseHolesViewModel> getHoles()
{
var holes = new List<CreateCourseHolesViewModel>();
for (int i =1; i < 19; i++)
{
holes.Add(new CreateCourseHolesViewModel { holeNumber = i });
}
return holes;
}
And I'm passing this into the view:
return PartialView("CreateCourseHoles", TempData["holes"]);
In the view I can loop through the list and display the whole number with a textbox next to each one to allow for the entry of par, si and distance.
var zHoles = TempData["holes"] as IEnumerable<BGSociety.Models.CreateCourseHolesViewModel>;
foreach (var hole in zHoles)
{
<div class="row">
<div class="col-sm-1">
<p>@hole.holeNumber</p>
</div>
<div class="col-sm-6">
<div class="form-group">
<div class="col-xs-12">
@Html.ValidationMessageFor(m => hole.par)
@Html.TextBox("par", TempData["par"], new { @class = "form-control", placeholder = "Par", name = "Par" })
</div>
</div>
</div>
</div>
}
But I just can't work out how to pass this populated list back to the controller for me to enter the data into the DB.
There's a great chance that I've gone about this the wrong way (!) but if someone could spare a few minutes to assist that would be marvelous!
Thanks, Sx