JQuery Mask-Money does not work MVC5

I work in MVC5 with an ASP.NET project, so I want to implement MaskMoney jQuery from here Mask Money

First I load the jquery file and add it to my package

  bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                    "~/Scripts/jquery-{version}.js",
                  "~/Scripts/jquery.maskMoney.js"
                  ));

So, I call it a layout.

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

Finally, in my opinion, I call this using the @ script section at the end of my file:

   <script>
        $(function () {
        $('#Total').maskMoney();
    })
   </script>

And in my edit, I use id to identify it

@Html.EditorFor(model => model.Total, new { htmlAttributes = new { @class = "form-control", @type = "number",@id="Total", @min = "0", @Value="",  @required = "required" } }) 

but when I load the page, nothing happens, what am I doing wrong?

+4
source share
1 answer

Try marking the script in a function document.ready:

<script>
    $(document).ready(function() {
        $('#Total').maskMoney();
    });
</script>
0
source

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


All Articles