脚本未加载

时间:2016-06-02 11:11:40

标签: javascript jquery asp.net-mvc asp.net-mvc-3

大家好,我在一个可能很容易的问题上失去了很多时间,我敢打赌这是一件很简单的事情,所以在layout.cshtml中我加载了所有这样的脚本

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title - My ASP.NET Application</title>
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")

</head>
<body>
    <div class="navbar navbar-inverse navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                @Html.ActionLink("Application name", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
            </div>
            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                    <li>@Html.ActionLink("Home", "Index", "Home")</li>
                    <li>@Html.ActionLink("About", "About", "Home")</li>
                    <li>@Html.ActionLink("Contact", "Contact", "Home")</li>
                </ul>
                @Html.Partial("_LoginPartial")
            </div>
        </div>
    </div>
    <div class="container body-content">
        @RenderBody()
        <hr />
        <footer>
            <p>&copy; @DateTime.Now.Year - My ASP.NET Application</p>
        </footer>
</div>

@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/UserScripts")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
<script type="text/javascript" src="~/Scripts/bootstrap-filestyle.js"> </script>

此页面中的脚本将加载到buldeconfig中,如下所示:

 public class BundleConfig
{
    // For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862
    public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                    "~/Scripts/jquery-{version}.js"));

        bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                    "~/Scripts/jquery.validate*"));

        bundles.Add(new ScriptBundle("~/bundles/UserScripts").Include(
            "~/Scripts/CrowdTouring.js"));

        bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                    "~/Scripts/modernizr-*"));

        bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                  "~/Scripts/bootstrap.js",
                  "~/Scripts/respond.js"));

        bundles.Add(new StyleBundle("~/Content/css").Include(
                  "~/Content/bootstrap.css",
                  "~/Content/site.css"));
    }
}

一个奇怪的事情发生在CrowdTouring.cs上的jquery代码应该是2页,我的寄存器和我的edituser,在它正在工作的寄存器中禁用按钮,但在我的EditUser它不起作用我不知道为什么我已经尝试了一切:S

这是我的Jquery CrodwTouring.js

$(document).ready(function () {
$("#checky").click(function () {
    $("#RegisterBut").attr("disabled", !this.checked);
});

$("#TipoUtilizador").change(function () {
               console.log("a");
    if ($(this).val() == "Cliente") {
        $("#TextoTipoUtilizador").text('Crie desafios de inovação turística e obtenha melhores soluções a um preço mais acessível e de melhor qualidade');
    }
    if ($(this).val() == "Resolvedor") {
        $("#TextoTipoUtilizador").text('Crie Soluções para os desafios e obtenha uma grande variadade de prémios');
    }
    if ($(this).val() == "Avaliador") {
        $("#TextoTipoUtilizador").text('Avalie as soluções e ganhe notoriedade na plataforma');
    }
});

$("div.myclass").hover(function () {
    $(this).css("background-color", "red")
});

function readURL(input) {
    if (input.files && input.files[0]) {
        var reader = new FileReader();

        reader.onload = function (e) {
            $('#fotografia').attr('src', e.target.result);
        }

        reader.readAsDataURL(input.files[0]);
    }
}

$("#ImagePath").change(function () {
    console.log("x");
    readURL(this);
});

});

最后在我的editUser页面中,我在底部加载了类似的脚本

 <div class="form-group">
        <div class="col-md-offset-3 col-md-9">
            <input type="submit" value="Save" class="btn btn-default" />
        </div>
    </div>
</div>

    

}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>


@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
    @Scripts.Render("~/bundles/UserScripts")
}

1 个答案:

答案 0 :(得分:0)

此处,在layout.cshtml页面中,您正在页面末尾加载CrodwTouring.js,在editUser页面中,您将再次呈现该捆绑包。

尝试从@Scripts.Render("~/bundles/UserScripts")页面的@section中删除editUser