Free Code Snippets in C#, Net Framework, Office 365, ASP.Net,WPF, Visual Studio, SQL Server, Antivirus free
#

 

 

How to include a jQuery script in Asp.Net Core.

 

jQuery is pre-installed in Asp.Net Core under wwwroot-libs.

Therefore you only need to insert a <script> block at the desired position and insert functions into these jQuery.

 

Here's a simple alert warning after loading a page

 

jQuery script Block

<script type="text/javascript" src="~/lib/jquery/dist/jquery.js"></script>

<script>

    $(document).ready(function () {

        alert("This is a jQuery- Alert Test");

    });

</script>

 

 

When inserting jQuery, the path must be set to "~ / lib / jquery / dist / jquery.js". Where ~ is the wwwroot directory.

The jQuery script Block Code can simply be inserted at the bottom of the View page in Razor

 

 

jQuery in Asp Core

JQuery makes it easy to run javascript functions on the client browser.

jQuery is preinstalled in Asp.Net Core application under the directory wwwroot / lib / jquery / dist / jquery.js

 

jQuery is a simple collection of functions that javascript simply executes.

This allows ajax to be better managed and data to be run between client and server during sessions.

 

 

 

 

Complete View Code, Razor View

The jQuery script is at the very end

@model IWois_Core.Models.Notes_Edit_DataModel

 

@{

    ViewData["Title"] = "Edit";

    Layout = "~/Views/Shared/_Layout.cshtml";

}

 

<div style="margin-top:20px;">

    <div class="col-md-push-0" style="margin-right:20%">

        <form asp-action="Edit">

 

            <div class="form-group" style="text-align:center ">

                <input type="submit" value="Speichern" class="btn btn-default" />

                <a href="~/Notes/Details/@Model.IDNote" title="Ansicht" style="font-size:large; text-decoration:none;margin:10px;">Ansicht</a>

                <a href="~/Notes/Index_All" title="Liste" style="font-size:large; text-decoration:none;margin:10px;">Liste</a>

 

            </div>

            <br />

            <div asp-validation-summary="ModelOnly" class="text-danger"></div>

            <input type="hidden" asp-for="IDNote" />

            <div class="form-group">

                <label asp-for="Title" class="control-label"></label>

                <input asp-for="Title" class="form-control" />

                <span asp-validation-for="Title" class="text-danger"></span>

            </div>

            <div class="form-group">

                <label asp-for="Text" class="control-label"></label>

 

                <br />

                TextArea

                @Html.TextAreaFor(model => model.Text1, new { @class = "form-control", @rows = 4 })

                <br />

                Div

                <div contenteditable="true" id="Text3" name="Text3" style="height:200px;overflow:auto;">

                    @Model.Text1

                </div>

 

 

                <span asp-validation-for="Text" class="text-danger"></span>

            </div>

 

        </form>

    </div>

</div>

 

 

@section scripts {

    @{await Html.RenderPartialAsync("_ValidationscriptsPartial");}

}

 

<script type="text/javascript" src="~/lib/jquery/dist/jquery.js"></script>

<script>

    $(document).ready(function () {

        alert("This is a jQuery- Alert Test");

    });

</script>

 

Mobile
»
Integrate Asp.Net Core jQuery
»
ASP.Net Core: Package references in the .csproj file
»
ASP.Net Core: Where to find the database of projects
»
testSQL Server: Anmelden mit .\Sqlexpress

.

Contact for Jobs, Project Requests: raimund.popp@microsoft-programmierer.de