epv epv - 1 year ago 87
HTML Question

How to include a script into my cshtml file without all the script texts

I have a asp.net cshtml file but I have to include script html's with ids for my ngRoutes to work. So far my cshtml file looks like this:

<div ng-view></div>

<script type="text/ng-template id="one.html">
...very long html...
<script type="text/ng-template id="two.html">
...very long html...
<script type="text/ng-template id="three.html">
...very long html...
<script type="text/ng-template id="four.html">
...very long html...

I don't want to include all the script, but need it to display like a directive. How am I able to do something like...

<div ng-view></div>
<div ng-include="'one.html''"></div>
<div ng-include="'two.html''"></div>
<div ng-include="'three.html''"></div>

I've tried that way but it doesn't allow me to just include it in the razor file.

Answer Source

I assume you're using ngRoute. In this case you can set the template urls on the routeProvider during the config phase:

angular.module('yourmodule', ['ngRoute'])
.config(['$routeProvider', function ($routeProvider) {
        .when('/one', {
            templateUrl: 'one.html',
        .when('/two', {
            templateUrl: 'two.html',
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download