別の部分ビューからレンダリングしようとしている強い型の部分ビューがあります
@{ Html.RenderPartial("Days", Model.DaysOpen, new ViewDataDictionary()); }
以下のASP.NET MVC、厳密に型指定されたビュー、部分的なビュー パラメーターの不具合に基づいてアドバイスを続けてきました。
親 (センター) を作成することはできますが、子 (所有) 日エンティティを作成することはできません。
誰でもアドバイスを提供できますか
詳細.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>
}
と私の部分的なビュー (日)
@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>
CentreController の create アクション
public ActionResult Create()
{
if (!Security.HasPemission(Permission.CanCreateCentres)) return View("AccessDenied");
var model = new Centre();
return (IsAjax()) ? (ActionResult)PartialView("Details", model) : View(model);
}