VS2010 IntelliSense inside text/x-jquery-tmpl script templates

前端 未结 5 1600
北海茫月
北海茫月 2021-01-01 14:53

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

5条回答
  •  Happy的楠姐
    2021-01-01 15:23

    I created a helper method for ASP.NET MVC 3 that works like this, inspired by Html.BeginForm:

    within the view:

    @using (Html.BeginHtmlTemplate("templateId"))
    {
        
    enter template here
    }

    Anything within the @using scope will be syntax highlighted.

    The code for the helper:

    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));
        }
    }
    

提交回复
热议问题