根据特定日期禁用按钮

时间:2018-07-16 13:53:53

标签: c# jquery asp.net-mvc

我有一个带有“部分”的Razor页面。我想禁用创建按钮。基于终止日期。如果“终止日期”设置为今天之后,则将鼠标悬停在“创建附带信”上应会禁用该按钮,并添加一个Bootstrap工具提示。谁能为我提供一些有关如何最好地做到这一点的帮助?

    @section scripts {
    <script language="javascript" type="text/javascript">
        $(function () {
            var lastItem = $(".contractSideLetterPanel:last");
            var clickableTitle = lastItem.children(".panel-heading:first").find("a");

            clickableTitle.click();
        });


    </script>
}

@section additionalStyles {
    @Styles.Render("~/plugins/datatables/media/css/cssDatatables")
}

@section modal {

}

<article class="row">
    <h1 class="pageTitle artistHeader fw200 mb20 mt10">@ViewBag.Title</h1>

    <div class="col-md-12">
        <div class="panel panel-visible" id="sideLettersContainer">
            @* Header *@
            <div class="panel-heading createContentTitle">
                <div class="panel-title createLink">
                    <a href="@Url.Action("CreateSideLetter", "ClientSetup", new
                             {
                                 page = Model.PagingInfo.Page,
                                 take = Model.PagingInfo.Take,
                                 sortBy = Model.PagingInfo.SortPropertyName,
                                 sortAsc = Model.PagingInfo.SortAscending
                             })" data-container="body" data-toggle="tooltip" title="Add Side Letter" id="createSideLetterLink">
                        <span class="fa fa-file"></span>&nbsp; Create Side Letter
                    </a>
                </div>
            </div>

            @* body *@
            <div class="panel panel-visible tableContainer mbn">
                @Html.Partial("_SideLettersList", Model)
            </div>

            @* Footer *@
            <div class="panel-footer text-center">
                <a href='@Url.Action("Contracts", "ClientSetup", new
                         {
                             page = Model.PagingInfo.Page,
                             take = Model.PagingInfo.Take,
                             sortBy = Model.PagingInfo.SortPropertyName,
                             sortAsc = Model.PagingInfo.SortAscending,
                             name = Model.SearchModel.Name,
                             createdby = Model.SearchModel.CreatedBy,
                             contractType = Model.SearchModel.ContractType,
                             dateFrom = Model.SearchModel.DateFrom,
                             dateTo = Model.SearchModel.DateTo
                         }
                             )' class="btn btn-primary" id="doneWithSideLettersLink">Done</a>
            </div>
        </div>
    </div>
</article>

部分

<div class="panel-group accordion accordion-lg mbn" id="sideLetterAccordion">
@* Contract Panel *@
@if (Model.OriginalContract != default(ContractDisplayModel))
{
    <div class="panel contractSideLetterPanel mtn">
        <div class="panel-heading sideLetterHeading">
            <a class="accordion-toggle accordion-icon link-unstyled collapsed" data-toggle="collapse" data-parent="#sideLetterAccordion" href="#accord1">
                @GetTitle(Model.OriginalContract.SummaryInfo)
            </a>
        </div>
        <div id="accord1" class="panel-collapse collapse" style="height: 0px;">
            <div class="panel-body">
            @* START - Summary Information *@
            @if (Model.OriginalContract.SummaryInfo.Description != string.Empty)
            {
                <div class="row">
                    @Html.LabelFor(m => m.OriginalContract.SummaryInfo.Description, new { @class = "col-sm-2 control-label ptn" })
                    <div class="col-sm-10 form-control-static ptn pb5">
                        <span>@Model.OriginalContract.SummaryInfo.Description</span>
                    </div>
                </div>
            }
            <div class="row">
                @Html.LabelFor(m => m.OriginalContract.SummaryInfo.ContractType, new { @class = "col-sm-2 control-label ptn" })
                <div class="col-sm-10 form-control-static ptn pb5">
                    @{
                        var contractType = Model.OriginalContract.SummaryInfo.ContractType.GetEnumDescription();
                    }
                    <span>@contractType</span>
                </div>
            </div>
            <div class="row">
                @Html.LabelFor(m => m.OriginalContract.SummaryInfo.Currency, new { @class = "col-sm-2 control-label ptn" })
                <div class="col-sm-10 form-control-static ptn pb5">
                    <span>@Model.OriginalContract.SummaryInfo.Currency</span>
                </div>
            </div>
            <div class="row">
                @Html.LabelFor(m => m.OriginalContract.SummaryInfo.StartDate, new { @class = "col-sm-2 control-label ptn" })
                <div class="col-sm-4 form-control-static ptn pb5">
                    <span>@Model.OriginalContract.SummaryInfo.StartDate.ToString("D")</span>
                </div>
                @if (Model.OriginalContract.SummaryInfo.EndDate != default(DateTime?))
                {
                    @Html.LabelFor(m => m.OriginalContract.SummaryInfo.EndDate, new { @class = "col-sm-2 control-label ptn" })
                    <div class="col-sm-4 form-control-static ptn pb5">
                        <span>@(Model.OriginalContract.SummaryInfo.EndDate != default(DateTime) ? ((DateTime)Model.OriginalContract.SummaryInfo.EndDate).ToString("D") : string.Empty)</span>
                    </div>
                }
            </div>
            @if (Model.OriginalContract.SummaryInfo.SignedDate != default(DateTime?))
            {
                <div class="row">
                    @Html.LabelFor(m => m.OriginalContract.SummaryInfo.SignedDate, new { @class = "col-sm-2 control-label ptn" })
                    <div class="col-sm-10 form-control-static ptn pb5">
                        <span>@(Model.OriginalContract.SummaryInfo.SignedDate != default(DateTime) ? ((DateTime)Model.OriginalContract.SummaryInfo.SignedDate).ToString("D") : string.Empty)</span>
                    </div>
                </div>
            }
            @if (Model.OriginalContract.SummaryInfo.NotificationDate != default(DateTime?))
            {
                <div class="row">
                    @Html.LabelFor(m => m.OriginalContract.SummaryInfo.NotificationDate, new { @class = "col-sm-2 control-label ptn" })
                    <div class="col-sm-10 form-control-static ptn pb5">
                        <span>@(Model.OriginalContract.SummaryInfo.NotificationDate != default(DateTime) ? ((DateTime)Model.OriginalContract.SummaryInfo.NotificationDate).ToString("D") : string.Empty)</span>
                    </div>
                </div>
            }
            @if (Model.OriginalContract.SummaryInfo.TerminationDate != default(DateTime?))
            {
                <div class="row">
                    @Html.LabelFor(m => m.OriginalContract.SummaryInfo.TerminationDate, new { @class = "col-sm-2 control-label ptn" })
                    <div class="col-sm-10 form-control-static ptn pb5">
                        <span>@(Model.OriginalContract.SummaryInfo.TerminationDate != default(DateTime) ? ((DateTime)Model.OriginalContract.SummaryInfo.TerminationDate).ToString("D") : string.Empty)</span>
                    </div>
                </div>
            }
            @if (Model.OriginalContract.SummaryInfo.PostTermCollectionEndDate != default(DateTime?))
            {
                <div class="row">
                    @Html.LabelFor(m => m.OriginalContract.SummaryInfo.PostTermCollectionEndDate, new { @class = "col-sm-2 control-label ptn" })
                    <div class="col-sm-10 form-control-static ptn pb5">
                        <span>@(Model.OriginalContract.SummaryInfo.PostTermCollectionEndDate != default(DateTime) ? ((DateTime)Model.OriginalContract.SummaryInfo.PostTermCollectionEndDate).ToString("D") : string.Empty)</span>
                    </div>
                </div>
            }
            @* END - Summary Information *@

1 个答案:

答案 0 :(得分:0)

一种实现此目的的方法可能是在ViewModel上添加一个名为TerminationDateHasPassed之类的布尔属性。

public bool TerminationDateHasPassed{ get; set; }

在后面的代码中计算此新属性的值。像这样:

TerminationDateHasPassed = TerminationDate < DateTime.Now

在“部分剃刀”视图中,您可以基于此属性将禁用的bootsrtap类添加到“创建”按钮。

<a href="@Url.Action("CreateSideLetter", "ClientSetup", new
                             {
                                 page = Model.PagingInfo.Page,
                                 take = Model.PagingInfo.Take,
                                 sortBy = Model.PagingInfo.SortPropertyName,
                                 sortAsc = Model.PagingInfo.SortAscending
                             })" data-container="body" data-toggle="tooltip"
title="Add Side Letter" id="createSideLetterLink"
class=@(Model.TerminationDateHasPassed ? "disabled": "")>
                        <span class="fa fa-file"></span>&nbsp; Create Side Letter
                    </a>