Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Javascript code not working in partial views!

$
0
0

Hi

in my Index view, i load a partial view with jquery.get method. it works correctly. my problem is that in my partialView i've used some javascript code which not working!

here is my simple partial view javascript code :

@model IEnumerable<Orders><button type="button" id="btnNew" class="btn btn-success btn-sm" onclick="newOrderItem()">Create new</button><br /><table class="table table-bordered"><tr><th>Order ID</th><th>Order Number</th><th>Order Date</th><th>Commands</th></tr>
    @if (Model != null)
    {
        foreach (var item in Model)
        {<tr><td>@item.OrderId</td><td>@item.OrderNumber</td><td>@item.OrderDate.Value.ToShamsiDate()</td><td>                   </td></tr>
        }
    }</table>

@section Scripts {
    
    <script src="~/lib/jquery/dist/jquery.min.js"></script><script>
        function newOrderItem() {
            alert('Hii');
        }</script>

}

As u see in my code, i have a button, in click event call javascript function with simple alert, but at runTime i'm facing this error in console :

ReferenceError: newOrderItem is not defined

I'm also include jquery file in my partial view, but i'm facing the same problem!

Where is my problem & how to solve it?

Thanks in advance


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>