VS2010 IntelliSense内在text/x-jquery-tmpl脚本模板 [英] VS2010 IntelliSense inside text/x-jquery-tmpl script templates
本文介绍了VS2010 IntelliSense内在text/x-jquery-tmpl脚本模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在使用我绝对喜欢使用的jQuery模板.从IDE的角度来看,唯一的缺点是script标记内缺少HTML IntelliSense.有没有办法欺骗VS2010,以便模板脚本标记中的标记获得IntelliSense和语法突出显示?
I've been using jQuery templates which I absolutely love to use. The only drawback from an IDE standpoint is the lack of HTML IntelliSense inside the script tag. Is there a way to fool VS2010 so that markup inside template script tags get IntelliSense and syntax highlighting?
推荐答案
受Html.BeginForm的启发,我为ASP.NET MVC 3创建了一个辅助方法,其工作原理如下:
I created a helper method for ASP.NET MVC 3 that works like this, inspired by Html.BeginForm:
在视图内:
@using (Html.BeginHtmlTemplate("templateId"))
{
<div>enter template here</div>
}
@using范围内的所有内容都会突出显示语法.
Anything within the @using scope will be syntax highlighted.
帮助程序的代码:
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));
}
}
这篇关于VS2010 IntelliSense内在text/x-jquery-tmpl脚本模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文