0

I am using JQuery UI Dialog function to load a partial view. The Dialog form contains input controls that holds data to saved in database. I am trying to get the values from the controls to post them as below:

<script type="text/javascript">
    function SaveItem() {
        var name = $("#Name").val();
        var price = $("#Price").val();
    }
</script>

When clicking create button that triggers the SaveItem Function: it gives this error:

Create:35 Uncaught ReferenceError: $ is not defined

I am already rendering the jquery libraries in _Layout.cshtml. I know that this partial view will not have those libraries since its loaded out side the main container.

So, how we can do that, what is the best practice? Is there a way other than including the jquery library again in the partial view?

7
  • First of all, don't put jquery library in your partial view too. Commented Aug 7, 2016 at 5:09
  • Where the script is located? Is it in your partial view? Commented Aug 7, 2016 at 5:11
  • this script is in partial view. @VahidNaderi so what is the answer? Commented Aug 7, 2016 at 5:22
  • How do you load that partial view? Can provide that script too. Commented Aug 7, 2016 at 5:51
  • Scripts should never be in partials (only the main view or layout)
    – user3559349
    Commented Aug 7, 2016 at 5:52

0