保持正确的HTML语法高亮上述<&脚本GT; " text / html的"模板 [英] Keep correct HTML syntax highlighting in <script> "text/html" templates

查看:172
本文介绍了保持正确的HTML语法高亮上述<&脚本GT; " text / html的"模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法留住的剃须刀里面看法在JavaScript的HTML模板HTML / ASP.net语法高亮和code完成?

Is there a way to retain HTML/ASP.net syntax highlighting and code completion within JavaScript HTML templates inside of razor views?

要帮助高亮(双关语意)的问题,看到问题的这一形象:

To help highlight (pun intended) the problem see this image of the problem:

编辑:这问题涉及到Visual Studio 2010

This questions relates to Visual Studio 2010.

推荐答案

为它创建一个帮手,在如图所示的语法高亮,在Visual Studio 2010中的应用MVC3 HTML模板脚本标记。

Create a helper for it, as shown on Syntax highlighting for script tags with html templates in Visual Studio 2010 MVC3 applications.

以从那里code,这里有什么是该链接的要领。

Taking the code from there, here are the essentials of what is at that link.

首先,添加了一些code到你的 HtmlHelperExtensions

First, add some code to your HtmlHelperExtensions:

public static class HtmlHelperExtensions
{
    public static ScriptTag BeginHtmlTemplate(this HtmlHelper helper, string id)
    {
        return new ScriptTag(helper, "text/html", id);
    }
}

public class ScriptTag : IDisposable
{
    private readonly TextWriter writer;

    private readonly TagBuilder builder;

    public ScriptTag(HtmlHelper helper, string type, string id)
    {
        this.writer = helper.ViewContext.Writer;
        this.builder = new TagBuilder("script");
        this.builder.MergeAttribute("type", type);
        this.builder.MergeAttribute("id", id);
        writer.WriteLine(this.builder.ToString(TagRenderMode.StartTag));
    }

    public void Dispose()
    {
        writer.WriteLine(this.builder.ToString(TagRenderMode.EndTag));
    }
}

现在你可以使用它像一个 Html.BeginForm()

Now you can use it like an Html.BeginForm():

@using (Html.BeginHtmlTemplate("person-template"))
{
    <h3>Heading</h3>
    <p>Credits: <span></span></p>
}

瞧!从Visual Studio中隐藏的相关部分语法高亮。

Voila! Syntax highlighting by hiding the relevant parts from Visual Studio.

这篇关于保持正确的HTML语法高亮上述&lt;&脚本GT; &QUOT; text / html的&QUOT;模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆