4

I have just started working on MVC. Today I tried writing a test application just to show a Jquery Dialog whenever I click on a button. I created a web project in Visual Studio 2013 and selected MVC template. in Index.cshtml I have following code. I included all the ui related js files from downloading from jqueryui.com

@{
ViewBag.Title = "Home Page";
}
<link href="~/Scripts/jquery-ui.css" rel="stylesheet" />
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/jquery-ui.js"></script>
<div id="dialog" title="Basic dialog">
<p> This is a basic dialog.</p>
</div>
<button type="button" id="open">Click Me.</button>
<script type="text/javascript">
    $(document).ready(function () {
    $("#open").click(function () {
        $("#dialog").dialog();
    });
});
</script>

When I tried to run above code it didn't worked at all. But when I commented following line in _Layout.cshtml it worked.

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

I tried commenting the include script section in Index.cshtml file without commenting above line but it didn't worked. The dialog only shows when I comment above line.

Can anybody tell me what is the issue here or any link to the resource where I can get more information about this issue?

1
  • 1
    Take a look at the App_Start\BundleConfig.cs file included in your project, where all the scripts you are using may already be loaded. You may have created a conflict when adding your js/css in you index.cshtml instead of in the BundleConfig Commented Aug 26, 2014 at 11:16

1 Answer 1

3

Don't include js/css file on view,just make its bundle(i think js/css files are there in bundleconfig and you are also explicitely including them in view and that is why they js files are conflicting) just render bundles on Layout page with @Scripts.Render("~/bundles/jquery") and then use below code on your view :-

Use @section scripts{ } in .cshtml as :-

 @section scripts{
   <script type="text/javascript">
    $(document).ready(function () {
      $("#open").click(function () {
       $("#dialog").dialog();
     });
   });
   </script>
 }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.