A simple jQuery autocomplete example does not work in an ASP.NET application

This thread is linked to my previous thread ( Using the push clause mechanism using JavaScript and jQuery (ASP.NET MVC project ). But the problem I am experiencing is too great to place it there.

I am trying to run a simple jQuery autocomplete example ( http://jqueryui.com/autocomplete/ ) to work in my ASP.NET NVC 4 webapp. I tried this:

@model PoliticiOnline.DTO.Question

@{
    ViewBag.Title = "Stel een vraag!";
}

<head>
    <link rel="stylesheet" href="~/Content/Questions.css" type="text/css" />

    <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
    <script src="//code.jquery.com/jquery-1.9.1.js"></script>
    <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

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


    <script>
        $(function () {
            var availableTags = [
                "ActionScript",
                "AppleScript",
                "Asp",
                "BASIC",
                "C",
                "C++",
                "Clojure",
                "COBOL",
                "ColdFusion",
                "Erlang",
                "Fortran",
                "Groovy",
                "Haskell",
                "Java",
                "JavaScript",
                "Lisp",
                "Perl",
                "PHP",
                "Python",
                "Ruby",
                "Scala",
                "Scheme"
            ];
            $("#tags").autocomplete({
                source: availableTags
            });
        });
    </script>

</head>

<h2>Stel een vraag!</h2>

@using (Html.BeginForm()) {
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>Vraag</legend>

        <div class="general-question">
            <div class="editor-label">
                @Html.LabelFor(model => model.GeneralQuestion, "Algemene Vraag")
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.GeneralQuestion, new{@class = "general-question-edit"})
                @Html.ValidationMessageFor(model => model.GeneralQuestion)
            </div>
        </div>

        <div class="geadresseerde-politici">
            @Html.Label("Politicus")
            @Html.DropDownListFor(model => model.PoliticianId, (SelectList)ViewBag.PolIds)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Explanation, "Extra Uitleg")
        </div>
        <div class="editor-field">
            @Html.TextAreaFor(model => model.Explanation, new{@class = "explanation-textarea-edit"})
            @Html.ValidationMessageFor(model => model.Explanation)
        </div>

        <p>
            <input type="submit" value="Indienen!" />
        </p>

        <label for="tags">Tags: </label>
        <input id="tags"/>
    </fieldset>
}

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

It's just autocomplete that doesn't work (I'm not trying to submit it using the form yet, I just want autocomplete to work).

When I start typing in the input box, nothing happens, but this shoudl really gives suggestions.

+4
1

:

"Uncaught ReferenceError: Uncaught ReferenceError: jQuery is not defined Uncaught ReferenceError: jQuery is not defined Uncaught ReferenceError: $ is not defined

, jquery .

jquery CDN - :

<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>

:

 $(document).ready(function () { }
+3

Source: https://habr.com/ru/post/1534895/


All Articles