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

前端 未结 5 1583
北海茫月
北海茫月 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条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-01 15:06

    If you're using MVC you can make an extension method for the HtmlHelper like this:

    public static class HtmlExtensions
    {
         public static MvcHtmlString Template(this HtmlHelper htmlHelper, string id, Func content)
         {
             var sb = new StringBuilder();
             sb.AppendFormat("");
    
             return new MvcHtmlString(sb.ToString());
         }
    }
    

    Use like

    @Html.Template("whatever", @
        template stuff here
    )
    

    You'll get full syntax coloring and intellisense that way. (though, VS might warn about invalid nesting of html elements depending on what your templates consist of)

提交回复
热议问题