0

I'm not really sure why this is not working but I have an MVC View that I want to display the current date/time/seconds on the page. I've put the javascript in the "Scripts/script.js" file. I then added the following at the bottom of the MVC View.

@section scripts {

    <script src="~/Scripts/script.js"></script>

    <script type="text/javascript">

        $(document).ready(function () {
            setDateTimer();
        });

    </script>

}

Thing is when I run it something is causing an error. Unfortunately at the moment I can't see the actual error message because of the way they have the site configured any error just takes you to a generic error page. I do know it has something to do with the code above because removing it cause the page to work.

For testing purposes I even removed all but simple javascript code in the file but that still doesn't work. Right now this is all that is in my script.js file.

function setDateTimer() {
    var today = new Date();
}

I know the name of the of the .js file in the code is correct because I just dragged and dropped it to the page from the solution explorer.

Here is most of my _Layout page.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="~/Content/Site.css" rel="stylesheet" />
</head>
<body>
        <div class="container body-content">
            @RenderBody()
            <footer></footer>
        </div>

        <script src="~/Scripts/jquery-1.10.2.min.js"></script>
        <script src="~/Scripts/bootstrap.min.js"></script>
        <script src="~/Scripts/modernizr-2.6.2.js"></script>
    </body>
</html>
2
  • what is the error? can you post your _Layout page? Commented Jul 5, 2016 at 19:24
  • I can't see the actual error right now because of the way the site is setup to send you to a generic error page. I striped out some stuff out of the Layout page and posted it but. All the relevant stuff is there. Commented Jul 5, 2016 at 20:02

1 Answer 1

1

Layout page doesn't have a place to render the section you can change it like

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="~/Content/Site.css" rel="stylesheet" />
</head>
<body>
        <div class="container body-content">
            @RenderBody()
            <footer></footer>
        </div>

        <script src="~/Scripts/jquery-1.10.2.min.js"></script>
        <script src="~/Scripts/bootstrap.min.js"></script>
        <script src="~/Scripts/modernizr-2.6.2.js"></script>
     @RenderSection("scripts",true)
    </body>
</html>
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect! That's what was missing.

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.