本文整理汇总了C#中ScriptManager.ListForType方法的典型用法代码示例。如果您正苦于以下问题:C# ScriptManager.ListForType方法的具体用法?C# ScriptManager.ListForType怎么用?C# ScriptManager.ListForType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ScriptManager
的用法示例。
在下文中一共展示了ScriptManager.ListForType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteScripts
public static MvcHtmlString WriteScripts(this HtmlHelper htmlHelper, string area = null)
{
const ScriptType type = ScriptType.JavaScript;
var catAppSetting = ConfigurationManager.AppSettings["SJ.Concatenate"];
bool concatenate = catAppSetting != null && bool.Parse(catAppSetting);
if (concatenate)
{
var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);
string url = urlHelper.Content("~/ScriptManager/" + type.ToString() + "/" + area);
var builder = new TagBuilder("script");
builder.Attributes.Add("type", "text/javascript");
builder.Attributes.Add("src", url);
return new MvcHtmlString(builder.ToString(TagRenderMode.Normal));
}
else
{
var manager = new ScriptManager();
string output = "";
foreach (var item in manager.ListForType(type).ScriptsForArea(area))
{
var builder = new TagBuilder("script");
builder.Attributes.Add("type", "text/javascript");
if (!item.IsInline)
{
builder.Attributes.Add("src", item.Url);
}
else
{
builder.InnerHtml = String.Format("/* {0} */\n", item.UniqueKey) + item.Source;
}
output += new MvcHtmlString(builder.ToString(TagRenderMode.Normal)) + "\n";
}
return new MvcHtmlString(output);
}
}
示例2: ScriptManager_ListForType_Creates_New_ScriptFileList_Test
public void ScriptManager_ListForType_Creates_New_ScriptFileList_Test()
{
var cacheManager = new Mock<ICacheManager>();
var contextAccessor = new Mock<IHttpContextAccessor>();
var list = new Mock<IScriptFileList>();
var items = new Dictionary<string, object>();
items.Add("__sm__Stylesheet", list.Object);
var context = new Mock<HttpContextBase>
{
DefaultValue = DefaultValue.Mock
};
contextAccessor.Setup(c => c.Current()).Returns(context.Object);
context.SetupGet(c => c.Items).Returns(items);
var target = new ScriptManager(cacheManager.Object, contextAccessor.Object);
var type = ScriptType.JavaScript;
IScriptFileList actual;
actual = target.ListForType(type);
Assert.IsNotNull(actual);
}
示例3: ScriptManager_ListForType_Returns_Existing_ScriptFileList_Test
public void ScriptManager_ListForType_Returns_Existing_ScriptFileList_Test()
{
var cacheManager = new Mock<ICacheManager>();
var contextAccessor = new Mock<IHttpContextAccessor>();
var list = new Mock<IScriptFileList>();
var context = new Mock<HttpContextBase>
{
DefaultValue = DefaultValue.Mock
};
contextAccessor.Setup(c => c.Current()).Returns(context.Object);
context.SetupGet(c => c.Application["__sm__JavaScript"]).Returns(() => list.Object);
var target = new ScriptManager(cacheManager.Object, contextAccessor.Object);
context.Object.Items["__sm__JavaScript"] = list.Object;
var type = ScriptType.JavaScript;
IScriptFileList actual;
actual = target.ListForType(type);
Assert.IsNotNull(actual);
Assert.AreSame(list.Object, actual);
}
示例4: WriteStyles
public static MvcHtmlString WriteStyles(this HtmlHelper htmlHelper, string area = null)
{
var type = ScriptType.Stylesheet;
var catAppSetting = ConfigurationManager.AppSettings["SJ.Concatenate"];
bool concatenate = catAppSetting != null && bool.Parse(catAppSetting);
if (concatenate)
{
var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);
string url = urlHelper.Content("~/ScriptManager/" + type.ToString() + "/" + area);
var builder = new TagBuilder("link");
builder.Attributes.Add("type", "text/css");
builder.Attributes.Add("rel", "stylesheet");
builder.Attributes.Add("href", url);
return new MvcHtmlString(builder.ToString(TagRenderMode.SelfClosing));
}
else
{
var manager = new ScriptManager();
string output = "";
foreach (var item in manager.ListForType(type).ScriptsForArea(area))
{
if (!item.IsInline)
{
var builder = new TagBuilder("link");
builder.Attributes.Add("type", "text/css");
builder.Attributes.Add("rel", "stylesheet");
builder.Attributes.Add("href", item.Url);
output += builder.ToString(TagRenderMode.SelfClosing) + "\n";
}
else
{
var builder = new TagBuilder("style");
builder.Attributes.Add("type", "text/css");
builder.InnerHtml = item.Source;
output += builder.ToString(TagRenderMode.Normal) + "\n";
}
}
return new MvcHtmlString(output);
}
}