Q:

Datepicker didn't work in modal page without adding js code (.Net MVC4)

I have some problem with modal and datepicker. 
I already try to googled for it and try some of the suggestion but still didn't solved my problem. 
I use template from the internet, and use shared layout for sidebar / header&footer. 
I put all my css/js render script in my shared layout. 
I use another file for my modal, so there's 3 cshtml file for 1 page (Shared layout, main page, modal page) 
Here's the code that I use for datepicker :
<input type="text" id="datepicker" data-plugin-datepicker class="form-control">

This code works fine in the main page without adding any js code, but when the modal pops up it didn't shows anything if I don't put a js script inside the modal file. 
I have to use this code to make the datepicker working in my modal page :
<script>
        $(function () {
              $("#datepicker").datepicker();
        });
</script>

Is there's anything wrong with this? 
And I can't change the date format from mm/dd/yyyy into dd-mm-yyyy. 
I already use this code :
<script>
        $(function () {
              $("#datepicker").datepicker({
                  dateFormat: 'dd-mm-yy'});
        });
</script>

Anyone knows why the format not working? 
Thanks
Felix

A:

Your datepicker will only work on a page if you:
1) import a javascript file containing the datepicker javascript code on that page
2) you put the javascript code on the page like you said in your question.  
On your main page I am assuming the datepicker works because there is a javascript file (something.js) get imported to your main page by some line like this:
<script src="something.js"></script>

Inside this something.js, there is the same javascript code that makes your datepicker work.  So that's why you don't need to do the 2) option on your main page.  
But on your modal page, there isn't a line like that, so that's why you need to put the 
<script>
  $(function () {
      $("#datepicker").datepicker();
  });
</script>

to make it work, or you can import the javascript file to your modal page to make it work. 