1

我有一个强类型局部视图,我试图从另一个局部视图呈现

@{ 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 的创建动作

public ActionResult Create()
{
        if (!Security.HasPemission(Permission.CanCreateCentres)) return View("AccessDenied");

        var model = new Centre();
        return (IsAjax()) ? (ActionResult)PartialView("Details", model) : View(model);
    }
4

0 回答 0