Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8168275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:28:08+00:00 2026-06-06T20:28:08+00:00

My web application is ASP.NET MVC4 with Razor and Knockout.js. The view model hierarchy

  • 0

My web application is ASP.NET MVC4 with Razor and Knockout.js. The view model hierarchy is becoming rather deep and complicated and I am moving more towards using nested Knockout templates for the corresponding views (each with a for/each for its child templates, etc) rather than monolithic slabs of HTML.

Something that annoys me is that when using the Knockout template definition syntax of <script type="text/html" id="scary-template"> the contents loses its Razor syntax highlighting in Visual Studio because it is interpreted as script. The templates are complex enough without the text all being plain black as well.

Some approaches I have considered are using Html.Raw to output the opening and closing script tags, or HtmlHelper extensions like Html.BeginKOTemplate(id) .

I’m interested to hear how other ASP.NET MVC folks approach this. Am I being pedantic? In any case the next developer who needs to pick this solution up will probably thank me for caring.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T20:28:09+00:00Added an answer on June 6, 2026 at 8:28 pm

    I don’t use Visual Studio, but I have some suggestions that could work for you.

    Starting with Knockout 2.1, you can define a template using the textarea tag, which will support syntax highlighting in many editors (including two I use, phpDesigner and Notepad++). To make sure the textarea doesn’t actually display on the page, it must have the display:none style (or be in a container with that style).

    <textarea id="mytemplate" style="display:none">
        <div>template content</div>
    </textarea>
    

    or

    <div style="display:none">
        <textarea id="mytemplate">
            <div>template content</div>
        </textarea>
    </div>
    

    You can also use any tag such as div to define a template. But this adds some overhead. First, the template content will be parsed (and possibly modified) by the browser. Second, it will be parsed by Knockout unless you instruct it otherwise. You can do this by passing a container node to applyBindings that doesn’t contain the template nodes, or by creating a custom binding that bypasses bindings for the template (see allowBindings here). You will still need the display:none style, of course.

    <div style="display:none" data-bind="allowBindings:false">
        <div id="mytemplate">
            <div>template content</div>
        </div>
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my ASP.NET MVC 3 web application I am overriding the View name in
From a brand-new ASP.NET MVC 4 Beta Web Application, I'm re-arranging my folders to
We have a Web application (ASP.NET) which displays in some page links to miscellaneous
I have a Web Application (ASP.NET C# for .NET 3.5) that uses the Session
i have developed a web application asp.net C#. on a button click i am
I have a web application on ASP.NET (C#) that has some precompiled components. I've
I have a web application in Asp.Net. I've created my master page and inside
I am building a Web Application using asp.net (C#). I come from windows forms
I am building a web application using ASP.NET MVC that has two very distinct
I'm developing a web application using ASP .NET MVC 1.0 and jQuery (including the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.