I am new in MVC3 Razor and want to show running time on a view (index.cshtml). I use a javascript function and put it in _Layout.cshtml so all other \"home\" views can use
The last line of the datum function should return the time rather than setting the innerHTML:
return 'Jetzt ist: ' + stunden + ':' + minuten + ':' + sekunden;
and your HTML can then be something like this:
The time is: <script type="text/javascript">datum(uhr)</script>
You should move the code from _Layout.cshtml into a seperate .js file and add a reference to it.
Also, you should change the index.cshtml code to be this:
@section SideBar {
<p>
<ul>
<li><a href="Index.cshtml">Add Job</a></li>
<li><a href="About.cshtml">About</a></li>
</ul>
</p>
<p>
The time is: <span id="uhr"></span>
</p>
<script type="text/javascript">datum("uhr");</script>
}
JS Fiddle Example