MVC3 Razor: call javascript function from view

后端 未结 2 1501
忘掉有多难
忘掉有多难 2021-01-04 19:30

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

2条回答
  •  -上瘾入骨i
    2021-01-04 20:25

    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 {
    

    The time is:

    }

    JS Fiddle Example

提交回复
热议问题