我的JavaScript无法使用我的视图asp.net

时间:2015-07-22 09:58:03

标签: javascript jquery html asp.net asp.net-mvc-5

我的剃须刀视图中的JavaScript存在一些小问题。 我希望用户报告缺席,但是当他选择时间时我想要显示日期时间的纠察队,这样用户就不必手动输入日期。

我还希望它是两个不同的标签,第一个标签是用户将报告他的假期,另一个标签是他将看到较旧假期的报告。但现在一切都出现在了。我想让它与此类似: enter image description here

但现在“Begärdsemstrar”正好坐在“Begärsemester”下

这是我对javascript的看法

@using Salesweb.Common.Utilities
@model List<Salesweb.Common.Vacation>
@{
    ViewBag.Title = "Semester";
}

<script type="text/javascript" language="javascript">
    $(function () {
        $(function () {
            $('#fromDate').datepicker({
                showButtonPanel: true,
                changeMonth: true,
                changeYear: true,
                dateFormat: "yy-mm-dd",
                firstDay: 1,
                onSelect: function (dateText) {
                    $('#EndDate').datepicker('option', 'minDate', new Date(dateText));
                }
            });

            $('#toDate').datepicker({
                showButtonPanel: true,
                changeMonth: true,
                changeYear: true,
                dateFormat: "yy-mm-dd",
                firstDay: 1,
                onSelect: function (dateText) {
                    $('#EndDate').datepicker('option', 'minDate', new Date(dateText));
                }
            });

        });
    });

    $(function () {
        $("#tabs").tabs();
    });
</script>
<div class="page-container">
    <div class="page-content">
        <div class="container">
            <div class="row">
                <div class="col-md-12">
                    <div id="tabs">
                        <div class="portlet light">
                            <ul>
                                <li><a href="#tabs-new">Begär semester</a></li>
                                <li><a href="#tabs-list">Begärda semestrar</a></li>
                            </ul>

                            <div id="tabs-new">
                                @if (ViewData["posted"] == null)
                                {
                                    using (Html.BeginForm("Index", "Vacation", FormMethod.Post, new { enctype = "multipart/form-data" }))
                                    {
                                        <div class="portlet light">
                                            <div class="portlet-title">
                                                <div class="caption">
                                                    <span class="caption-subject font-green-sharp bold uppercase">Semester</span>
                                                </div>
                                            </div>
                                            <div class="portlet-body">
                                                <table class="table table-striped table-bordered table-hover">
                                                    <tr>
                                                        <td>Från:</td>
                                                        <td><input type="text" id="fromDate" name="fromDate" style="width: 70px" /></td>
                                                    </tr>
                                                    <tr>
                                                        <td>Till:</td>
                                                        <td><input type="text" id="toDate" name="toDate" style="width: 70px" /></td>
                                                    </tr>
                                                    <tr>
                                                        <td>Kommentar:</td>
                                                        <td><textarea id="comment" name="comment" style="width: 300px; height: 70px;" rows="5" cols="5"></textarea></td>
                                                    </tr>
                                                    <tr>
                                                        <td></td>
                                                        <td><input type="submit" value="Begär semester" id="submit" name="submit" /></td>
                                                    </tr>
                                                </table>
                                            </div>
                                        </div>
                                    }

                                }
                                else
                                {
                                    <h2 style="color: Green"> Semestern begärd.</h2>
                                    @Html.ActionLink("Begär ny semester", "Index")
                                }
                            </div>

                            <div id="tabs-list">
                                <div class="portlet light">
                                    <div class="portlet-title">
                                        <div class="caption">
                                            <span class="caption-subject font-green-sharp bold uppercase">Semester</span>
                                        </div>
                                    </div>
                                    <div class="portlet-body">
                                        <table class="table table-striped table-bordered table-hover">
                                            <thead>
                                                <tr>
                                                    <th>Från</th>
                                                    <th>Till</th>
                                                    <th>Rapportera tid</th>
                                                    <th>Status</th>
                                                    <th>Kommentar</th>
                                                </tr>
                                            </thead>
                                            @foreach (var vacation in Model)
                                            {
                                                <tr>
                                                    <td>@(vacation.StartDate.ToShortDateString())</td>
                                                    <td>@(vacation.EndDate.ToShortDateString())</td>
                                                    <td>
                                                        @if (vacation.TimeReported)
                                                        {
                                                            <a>Tid har rapporterats</a>
                                                        }
                                                        else if (vacation.Status == (int)VacationStatus.Godkänd && !vacation.TimeReported)
                                                        {
                                                            <a href="@(Url.Action("Absent", "Reports", new { vacationId = vacation.VacationID }))">Rapportera tid</a>
                                                        }
                                                        else
                                                        {
                                                            <a>-</a>
                                                        }
                                                    </td>
                                                    <td>@(((VacationStatus)vacation.Status).ToString()) </td>
                                                    <td>@vacation.Comment</td>
                                                </tr>
                                            }
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

我在一个包中加载我的脚本

            bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                    "~/Scripts/modernizr-2.8.3",
                    "~/content/global/plugins/jquery.min.js",
                    "~/content/global/plugins/jquery-ui/jquery-ui.min.js",
                    "~/content/global/plugins/bootstrap/js/bootstrap.min.js",
                    "~/content/global/plugins/datatables/media/js/jquery.dataTables.min.js",
                    "~/content/global/plugins/datatables/extensions/TableTools/js/dataTables.tableTools.js",
                    "~/content/global/plugins/datatables/plugins/bootstrap/dataTables.bootstrap.js",
                    "~/content/global/scripts/metronic.js",
                    "~/content/admin/layout3/scripts/layout.js",
                    "~/content/admin/layout3/scripts/demo.js",
                    "~/content/admin/pages/scripts/table-advanced.js"
                    ));

而不是从我的_Layout.cshtml中加载这样的脚本。

 @Scripts.Render("~/bundles/modernizr")

1 个答案:

答案 0 :(得分:0)

你的jQuery文档就绪函数有点混乱/嵌套

$(function () {
    $('#fromDate').datepicker({
        showButtonPanel: true,
        changeMonth: true,
        changeYear: true,
        dateFormat: "yy-mm-dd",
        firstDay: 1,
        onSelect: function (dateText) {
            $('#EndDate').datepicker('option', 'minDate', new Date(dateText));
        }
    });

    $('#toDate').datepicker({
        showButtonPanel: true,
        changeMonth: true,
        changeYear: true,
        dateFormat: "yy-mm-dd",
        firstDay: 1,
        onSelect: function (dateText) {
            $('#EndDate').datepicker('option', 'minDate', new Date(dateText));
        }
    });
    $("#tabs").tabs();
});

我删除了重复的文档准备检查。试试我上面提供的代码。