I have a Strongly Types Partial View that I am trying to render from another Partial View
@{ Html.RenderPartial("Days", Model.DaysOpen, new ViewDataDictionary()); }
I have been folling advice based on the below ASP.NET MVC, strongly typed views, partial view parameters glitch
It allows me to create the parent(Centre) but does not create the Child (owned) Days entity.
Can anyone offer any advice
Details.cshtml
@model RCCMS.ObjectModel.Entities.Centre
@using (Html.BeginForm(null, null, FormMethod.Post, new { @class = "form-horizontal", Role = "form" }))
{
@Html.ValidationSummary("Please correct the following errors:-")
<div id="HiddenFields">
@Html.HiddenFor(m => m.RowVersion)
</div>
<fieldset>
<div class="form-group">
@Html.LabelFor(model => model.Name, new { @class = "col-md-2 control-label" })
<div class="col-md-5">
@Html.TextBoxFor(model => model.Name, new { @class = "form-control" })
</div>
<div class="col-md-1">
@Html.ValidationMessageFor(model => model.Name, "*")
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Address1, new { @class = "col-md-2 control-label" })
<div class="col-md-5">
@Html.TextBoxFor(model => model.Address1, new { @class = "form-control" })
</div>
<div class="col-md-1">
@Html.ValidationMessageFor(model => model.Address1, "*")
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Address2, new { @class = "col-md-2 control-label" })
<div class="col-md-5">
@Html.TextBoxFor(model => model.Address2, new { @class = "form-control" })
</div>
<div class="col-md-1">
@Html.ValidationMessageFor(model => model.Address2, "*")
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Address3, new { @class = "col-md-2 control-label" })
<div class="col-md-5">
@Html.TextBoxFor(model => model.Address3, new { @class = "form-control" })
</div>
<div class="col-md-1">
@Html.ValidationMessageFor(model => model.Address3, "*")
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Town, new { @class = "col-md-2 control-label" })
<div class="col-md-5">
@Html.TextBoxFor(model => model.Town, new { @class = "form-control" })
</div>
<div class="col-md-1">
@Html.ValidationMessageFor(model => model.Town, "*")
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.County, new { @class = "col-md-2 control-label" })
<div class="col-md-5">
@Html.TextBoxFor(model => model.County, new { @class = "form-control" })
</div>
<div class="col-md-1">
@Html.ValidationMessageFor(model => model.County, "*")
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Postcode, new { @class = "col-md-2 control-label" })
<div class="col-md-5">
@Html.TextBoxFor(model => model.Postcode, new { @class = "form-control" })
</div>
<div class="col-md-1">
@Html.ValidationMessageFor(model => model.Postcode, "*")
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Uprn, new { @class = "col-md-2 control-label" })
<div class="col-md-5">
@Html.TextBoxFor(model => model.Uprn, new { @class = "form-control" })
</div>
<div class="col-md-1">
@Html.ValidationMessageFor(model => model.Uprn, "*")
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Lunch, new { @class = "col-md-2 control-label" })
<div class="col-md-5">
@Html.TextBoxFor(model => model.Lunch, new { @class = "form-control" })
</div>
<div class="col-md-1">
@Html.ValidationMessageFor(model => model.Lunch, "*")
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.VoluntaryContribution, new { @class = "col-md-2 control-label" })
<div class="col-md-5">
@Html.TextBoxFor(model => model.VoluntaryContribution, new { @class = "form-control" })
</div>
<div class="col-md-1">
@Html.ValidationMessageFor(model => model.VoluntaryContribution, "*")
</div>
</div>
@{ Html.RenderPartial("Days", Model.DaysOpen, new ViewDataDictionary()); }
<div class="col-md-offset-2">
<input type="submit" name="submit" value="Save" class="btn btn-primary"/>
<input type="submit" id="cancel" name="submit" value="Cancel" class="btn"/>
</div>
</fieldset>
}
And my Partial View (Days)
@model RCCMS.ObjectModel.Entities.Days
<div class="form-group">
@Html.Label("Days Open", new {@class = "col-md-5 control-label"})
<div class="col-md-10">
<div class="checkbox-inline">
<label>
@Html.CheckBoxFor(m => m.Monday) Monday
@Html.ValidationMessageFor(m => m.Monday, "*")
</label>
</div>
<div class="checkbox-inline">
<label>
@Html.CheckBoxFor(m => m.Tuesday) Tuesday
@Html.ValidationMessageFor(m => m.Tuesday, "*")
</label>
</div>
<div class="checkbox-inline">
<label>
@Html.CheckBoxFor(m => m.Wednesday) Wednesday
@Html.ValidationMessageFor(m => m.Wednesday, "*")
</label>
</div>
<div class="checkbox-inline">
<label>
@Html.CheckBoxFor(m => m.Thursday) Thursday
@Html.ValidationMessageFor(m => m.Thursday, "*")
</label>
</div>
<div class="checkbox-inline">
<label>
@Html.CheckBoxFor(m => m.Friday) Friday
@Html.ValidationMessageFor(m => m.Friday, "*")
</label>
</div>
<div class="checkbox-inline">
<label>
@Html.CheckBoxFor(m => m.Saturday) Saturday
@Html.ValidationMessageFor(m => m.Saturday, "*")
</label>
</div>
<div class="checkbox-inline">
<label>
@Html.CheckBoxFor(m => m.Sunday) Sunday
@Html.ValidationMessageFor(m => m.Sunday, "*")
</label>
</div>
</div>
The create action of the CentreController
public ActionResult Create()
{
if (!Security.HasPemission(Permission.CanCreateCentres)) return View("AccessDenied");
var model = new Centre();
return (IsAjax()) ? (ActionResult)PartialView("Details", model) : View(model);
}