使用Bootstrap Modal如何渲染

时间:2015-06-06 15:29:25

标签: asp.net-mvc twitter-bootstrap asp.net-mvc-4 asp.net-mvc-partialview

我遇到了一个大问题。我只想在我的索引视图中使用我的创建 - 查看新的VacationRequests

我不可能在一个视图中有两个不同的模型。

@*@model System.Collections.Generic.IEnumerable<AppEule.Models.VacationRequest>*@
@model System.Collections.Generic.IEnumerable<GUIManagement.EmployeeVacationRequestViewItem>

@using System.Collections
@using System.Collections.Generic
@using AppEule.Models
@using TestAjax.Helpers

<h2>
    @{ViewBag.Title = "Urlaubsanträge";}
</h2>

@*<p>
    @Html.ActionLink("Create New", "Create")
</p>*@

<div class="table-responsive">


    <table id="mytable" class="table table-bordred table-striped">

        <thead>

            <th>Zeitraum</th>
            <th>Urlaubstage</th>
            <th>Vertreter</th>
            <th>Status</th>
            <th></th>
            <th></th>
        </thead>

        <tbody>

            @foreach (var item in Model)
            {
                <tr>
                    <td class="col-md-4">
                        @Html.DisplayFor(modelItem => item.VacationStartDateViewString) - @Html.DisplayFor(modelItem => item.VacationEndDateViewString)
                    </td>
                    <td class ="col-md-1">
                        @Html.DisplayFor(modelItem => item.NetVacationDaysViewString)
                    </td>
                    <td class="col-md-3">
                        @Html.DisplayFor(modelItem => item.ShiftPartnerFullName)
                    </td>
                    <td class="col-md-2">
                        @Html.DisplayFor(modelItem => item.VacationRequestProcessingStateViewString)
                    </td>
                    <td class="col-md-1">
                        @Html.NoEncodeActionLink("<span class='fa fa-info'></span>", "Details aneigen", "Details", "VacationRequests", routeValues: new { id = item.VacationRequestID }, htmlAttributes: new { @class = "btn btn-primary btn_small btn-sm" })
                    </td>

                    <td class="col-md-1">
                        @Html.NoEncodeActionLink("<span class='fa fa-ban'></span>", "Urlaubsantrag stornieren", "Delete", "VacationRequests", routeValues: new { id = item.VacationRequestID }, htmlAttributes: new { @class = "btn btn-danger btn_small btn-sm" })
                    </td>
                </tr>
            }
        </tbody>  
    </table>
    @Html.RenderPartial("~/Views/VacationRequests/_CreateVacationRequest.cshtml",  VacationManagement.VacationRequest() Vac);
</div>

如何访问或渲染局部视图?

@Html.RenderPartial("~/Views/VacationRequests/_CreateVacationRequest.cshtml", VacationManagement.VacationRequest() Vac);

这是局部视图。

@using System
@using System.Activities.Expressions

@model VacationManagement.VacationRequest

@{
    Layout = null;
}

<div class="modal fade" id="add" tabindex="-1" role="dialog" aria-labelledby="edit" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button>
            <div class="modal-header">
                <img src="~/Content/images/logo_dash.png" class="img-responsive center-block" alt="Responsive image">
                <h4 class="modal-title custom_align" id="Heading">Urlaubsantrag stellen</h4>
            </div>
            <div class="modal-body">
                @using (Html.BeginForm())
                {
                    @Html.AntiForgeryToken()
                    @*  @Html.AntiForgeryToken()*@
                    @Html.EditorFor(model => model.EmployeeID, new { htmlAttributes = new { @class = "form-control datepicker" } })
                    <div class="form-horizontal">
                        @Html.LabelFor(model => model.VacationStartDate, "Urlaubsbeginn", htmlAttributes: new { @class = "control-label" })
                        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
                        <div class="form-group">
                            <div class="col-md-12">
                                @Html.EditorFor(model => model.VacationStartDate, new { htmlAttributes = new { @class = "form-control datepicker" } })
                                @Html.ValidationMessageFor(model => model.VacationStartDate, "", new { @class = "text-danger" })
                            </div>
                        </div>
                        @Html.LabelFor(model => model.VacationEndDate, "Urlaubsende", htmlAttributes: new { @class = "control-label" })
                        <div class="form-group">
                            <div class="col-md-12">
                                @Html.EditorFor(model => model.VacationEndDate, new { htmlAttributes = new { @class = "form-control datepicker" } })
                                @Html.ValidationMessageFor(model => model.VacationEndDate, "", new { @class = "text-danger" })
                            </div>
                        </div>
                    </div>
                    <input type="submit" value="Create" class="btn btn-default" />
                }
            </div>
            <div class="modal-footer ">
                <button type="submit" value="Create" class="btn btn-success"> Speichern</button>
            </div>
        </div>
    </div>
</div>
<div>
    @Html.ActionLink("Back to List", "Index")
</div>

1 个答案:

答案 0 :(得分:0)

您需要将VacationManagement.VacationRequest的实例传递给局部视图。改变这个

@Html.RenderPartial("~/Views/VacationRequests/_CreateVacationRequest.cshtml", VacationManagement.VacationRequest() Vac);

到这个

@{ Html.RenderPartial("_CreateVacationRequest", new VacationManagement.VacationRequest()); }