ASP.NET Razor Helpers API Reference

Mike Pope, 19 October 2010

This is a sort of an experiment I did to play around with creating an API reference for the ASP.NET Web Pages/Razor helpers. More about the API ref is on the blog.

Built-in helpers are in the System.Web.Helpers.dll assembly except as noted. Helpers marked with "(TK)" are in the Microsoft Web Helpers library/toolkit (aka the Microsoft.Web.Helpers.dll assembly), which you have to install separately. See WebMatrix Beta 2 tip: why can't I use helpers?.

Namespace is System.Web.Helpers for built-in helpers and Microsoft.Web.Helpers for toolkit helpers (again, unless otherwise noted).

See the notes at the end for information about how this information was gathered.

Analytics, AntiForgery, Bing, Chart, ChartTheme, Crypto, Database, DynamicJsonArray, DynamicJsonObject, Facebook, FileUpload, GamerCard, Gravatar, GravatarRating, HttpAntiForgeryException, Json, LinkShare, LinkShareSite (enum), ObjectInfo, PreApplicationStartCode, ReCaptcha, ServerInfo, SortDirection (enum), StringExtensions, Themes, Twitter, Validation, Video, WebCache, WebGrid, WebGridColumn, WebGridPagerModes (enum), WebGridRow, WebImage, WebMail, WebSecurity

 

Analytics (TK)

Renders the analytics JavaScript code for the specified provider and ID. Requires registration with that provider.

Methods

public static HtmlString GetGoogleHtml(string webPropertyId);

public static HtmlString GetStatCounterHtml(int project, string security);

public static HtmlString GetYahooHtml(string account);

AntiForgery

Renders and tests a token that verifies that a page is not being spoofed. See WEBMATRIX–HELPERS–ANTIFORGERY.

Methods

public static HtmlString GetHtml([Optional, DefaultParameterValue(null)] string salt);

public static void Validate([Optional, DefaultParameterValue(null)] string salt);

Bing (TK)

Passes a search to Bing. The AdvancedSearchBox method renders the results in the current page. Optionally lets you specify a URL to search.

Methods

static Bing();

public static IHtmlString AdvancedSearchBox(
[Optional, DefaultParameterValue(
null)] string siteUrl,
[Optional, DefaultParameterValue(
null)] string siteName,
[Optional, DefaultParameterValue(0x142)]
int boxWidth,
[Optional, DefaultParameterValue(600)]
int resultWidth,
[Optional, DefaultParameterValue(400)]
int resultHeight,
[Optional, DefaultParameterValue(
"Blue")] string themeColor,
[Optional, DefaultParameterValue(
"en-US")] string locale);

public static IHtmlString SearchBox(
[Optional, DefaultParameterValue(
null)] string siteUrl,
[Optional, DefaultParameterValue(0x142)]
int boxWidth);

Chart

Renders a chart based on an array, an XML file, or database data.

Methods

public Chart(
int
width,
int
height,
[Optional, DefaultParameterValue(
null)] string template,
[Optional, DefaultParameterValue(
null)] string templatePath);

public Chart AddLegend(
[Optional, DefaultParameterValue(
null)] string title,
[Optional, DefaultParameterValue(
null)] string name);

public Chart AddSeries(
[Optional, DefaultParameterValue(
null)] string name,
[Optional, DefaultParameterValue(
"Column")] string chartType,
[Optional, DefaultParameterValue(
null)] string chartArea,
[Optional, DefaultParameterValue(
null)] string axisLabel,
[Optional, DefaultParameterValue(
null)] string legend,
[Optional, DefaultParameterValue(1)]
int markerStep,
[Optional, DefaultParameterValue(
null)] IEnumerable xValue,
[Optional, DefaultParameterValue(
null)] string xField,
[Optional, DefaultParameterValue(
null)] IEnumerable yValues,
[Optional, DefaultParameterValue(
null)] string yFields);

public Chart AddTitle(
[Optional, DefaultParameterValue(
null)] string text,
[Optional, DefaultParameterValue(
null)] string name);

public Chart DataBindCrossTable(
IEnumerable dataSource,
string groupByField,
string xField,
string yFields,
[Optional, DefaultParameterValue(
null)] string otherFields,
[Optional, DefaultParameterValue(
"Ascending")] string pointSortOrder);

public Chart DataBindTable(
IEnumerable dataSource,
[Optional, DefaultParameterValue(
null)] string xField);

public byte[] GetBytes([Optional, DefaultParameterValue("jpeg")] string format);

public static Chart GetFromCache(string key);

public Chart Save(
string
path,
[Optional, DefaultParameterValue(
"jpeg")] string format);

public string SaveToCache(
[Optional, DefaultParameterValue(
null)] string key,
[Optional, DefaultParameterValue(20)]
int minutesToCache,
[Optional, DefaultParameterValue(
true)] bool slidingExpiration);

public Chart SaveXml(string path);

public Chart SetXAxis(
[Optional, DefaultParameterValue(
"")] string title,
[Optional, DefaultParameterValue(0.0)]
double min,
[Optional, DefaultParameterValue((
double) 1.0 / (double) 0.0)] double max);

public Chart SetYAxis(
[Optional, DefaultParameterValue(
"")] string title,
[Optional, DefaultParameterValue(0.0)]
double min,
[Optional, DefaultParameterValue((
double) 1.0 / (double) 0.0)] double max);

public WebImage ToWebImage([Optional, DefaultParameterValue("jpeg")] string format);

public Chart Write([Optional, DefaultParameterValue("jpeg")] string format);

public static Chart WriteFromCache(
string key,
[Optional, DefaultParameterValue(
"jpeg")] string format);

 

Properties

public string FileName { get; }

public int Height { get; }

public int Width { get; }

ChartTheme

Defines built-in formatting for a chart.

Fields

public const string Blue = "<Chart BackColor=\"#D3DFF0\" BackGradientStyle=\"TopBottom\" BackSecondaryColor=\"White\" BorderColor=\"26, 59, 105\" BorderlineDashStyle=\"Solid\" BorderWidth=\"2\" Palette=\"BrightPastel\">\r\n <ChartAreas>\r\n <ChartArea Name=\"Default\" _Template_=\"All\" BackColor=\"64, 165, 191, 228\" BackGradientStyle=\"TopBottom\" BackSecondaryColor=\"White\" BorderColor=\"64, 64, 64, 64\" BorderDashStyle=\"Solid\" ShadowColor=\"Transparent\" /> \r\n </ChartAreas>\r\n <Legends>\r\n <Legend _Template_=\"All\" BackColor=\"Transparent\" Font=\"Trebuchet MS, 8.25pt, style=Bold\" IsTextAutoFit=\"False\" /> \r\n </Legends>\r\n <BorderSkin SkinStyle=\"Emboss\" /> \r\n </Chart>";

public const string Green = "<Chart BackColor=\"#C9DC87\" BackGradientStyle=\"TopBottom\" BorderColor=\"181, 64, 1\" BorderWidth=\"2\" BorderlineDashStyle=\"Solid\" Palette=\"BrightPastel\">\r\n <ChartAreas>\r\n <ChartArea Name=\"Default\" _Template_=\"All\" BackColor=\"Transparent\" BackSecondaryColor=\"White\" BorderColor=\"64, 64, 64, 64\" BorderDashStyle=\"Solid\" ShadowColor=\"Transparent\">\r\n <AxisY LineColor=\"64, 64, 64, 64\">\r\n <MajorGrid Interval=\"Auto\" LineColor=\"64, 64, 64, 64\" />\r\n <LabelStyle Font=\"Trebuchet MS, 8.25pt, style=Bold\" />\r\n </AxisY>\r\n <AxisX LineColor=\"64, 64, 64, 64\">\r\n <MajorGrid LineColor=\"64, 64, 64, 64\" />\r\n <LabelStyle Font=\"Trebuchet MS, 8.25pt, style=Bold\" />\r\n </AxisX>\r\n <Area3DStyle Inclination=\"15\" IsClustered=\"False\" IsRightAngleAxes=\"False\" Perspective=\"10\" Rotation=\"10\" WallWidth=\"0\" />\r\n </ChartArea>\r\n </ChartAreas>\r\n <Legends>\r\n <Legend _Template_=\"All\" Alignment=\"Center\" BackColor=\"Transparent\" Docking=\"Bottom\" Font=\"Trebuchet MS, 8.25pt, style=Bold\" IsTextAutoFit =\"False\" LegendStyle=\"Row\">\r\n </Legend>\r\n </Legends>\r\n <BorderSkin SkinStyle=\"Emboss\" />\r\n</Chart>";

public const string Vanilla = "<Chart Palette=\"SemiTransparent\" BorderColor=\"#000\" BorderWidth=\"2\" BorderlineDashStyle=\"Solid\">\r\n<ChartAreas>\r\n <ChartArea _Template_=\"All\" Name=\"Default\">\r\n <AxisX>\r\n <MinorGrid Enabled=\"False\" />\r\n <MajorGrid Enabled=\"False\" />\r\n </AxisX>\r\n <AxisY>\r\n <MajorGrid Enabled=\"False\" />\r\n <MinorGrid Enabled=\"False\" />\r\n </AxisY>\r\n </ChartArea>\r\n</ChartAreas>\r\n</Chart>";

public const string Vanilla3D = "<Chart BackColor=\"#555\" BackGradientStyle=\"TopBottom\" BorderColor=\"181, 64, 1\" BorderWidth=\"2\" BorderlineDashStyle=\"Solid\" Palette=\"SemiTransparent\" AntiAliasing=\"All\">\r\n <ChartAreas>\r\n <ChartArea Name=\"Default\" _Template_=\"All\" BackColor=\"Transparent\" BackSecondaryColor=\"White\" BorderColor=\"64, 64, 64, 64\" BorderDashStyle=\"Solid\" ShadowColor=\"Transparent\">\r\n <Area3DStyle LightStyle=\"Simplistic\" Enable3D=\"True\" Inclination=\"30\" IsClustered=\"False\" IsRightAngleAxes=\"False\" Perspective=\"10\" Rotation=\"-30\" WallWidth=\"0\" />\r\n </ChartArea>\r\n </ChartAreas>\r\n</Chart>";

public const string Yellow = "<Chart BackColor=\"#FADA5E\" BackGradientStyle=\"TopBottom\" BorderColor=\"#B8860B\" BorderWidth=\"2\" BorderlineDashStyle=\"Solid\" Palette=\"EarthTones\">\r\n <ChartAreas>\r\n <ChartArea Name=\"Default\" _Template_=\"All\" BackColor=\"Transparent\" BackSecondaryColor=\"White\" BorderColor=\"64, 64, 64, 64\" BorderDashStyle=\"Solid\" ShadowColor=\"Transparent\">\r\n <AxisY>\r\n <LabelStyle Font=\"Trebuchet MS, 8.25pt, style=Bold\" />\r\n </AxisY>\r\n <AxisX LineColor=\"64, 64, 64, 64\">\r\n <LabelStyle Font=\"Trebuchet MS, 8.25pt, style=Bold\" />\r\n </AxisX>\r\n </ChartArea>\r\n </ChartAreas>\r\n <Legends>\r\n <Legend _Template_=\"All\" BackColor=\"Transparent\" Docking=\"Bottom\" Font=\"Trebuchet MS, 8.25pt, style=Bold\" LegendStyle=\"Row\">\r\n </Legend>\r\n </Legends>\r\n <BorderSkin SkinStyle=\"Emboss\" />\r\n</Chart>";

Crypto

Creates a cryptographic hash value for the specified data. (See Cryptographic hash function.)

Methods

public static string GenerateSalt([Optional, DefaultParameterValue(0x10)] int byteLength);

public static string Hash(
byte[] input, [Optional,
DefaultParameterValue(
"sha256")] string algorithm);

public static string Hash(
string
input,
[Optional, DefaultParameterValue(
"sha256")] string algorithm);

public static string HashPassword(string password);

public static string SHA1(string input);

public static string SHA256(string input);

public static bool VerifyHashedPassword(string hashedPassword, string password);

Database [1]

Connects to a database and provides a way to execute SQL statements

Events

public static event EventHandler<ConnectionEventArgs> ConnectionOpened;

 

Methods

static Database();

public void Close();

public void Dispose();

protected virtual void Dispose(bool disposing);

public int Execute(string commandText, params object[] args);

[return: Dynamic]
public object GetLastInsertId();

public static Database Open(string name);

public static Database OpenConnectionString(
string
connectionString,
[Optional, DefaultParameterValue(
null)] string providerName);

[return: Dynamic(new bool[] { false, true })]
public IEnumerable<object> Query(
  
string commandText,
  
params object[] parameters);

[return: Dynamic]
public object QuerySingle(
  
string commandText,
  
params object[] args);

[return: Dynamic]
public object QueryValue(
   string
commandText,
   params object[] args);

 

Properties

public DbConnection Connection { get; }

DynamicJsonArray

TBD

Methods

public DynamicJsonArray(object[] arrayValues);

public IEnumerator GetEnumerator();

public static implicit operator object[](DynamicJsonArray obj);

public static implicit operator Array(DynamicJsonArray obj);

IEnumerator<object> IEnumerable<object>.GetEnumerator();

public override bool TryConvert(ConvertBinder binder, out object result);

public override bool TryGetMember(GetMemberBinder binder, out object result);

 

Properties

[Dynamic]
public object this[int index] { [return: Dynamic] get; [param: Dynamic] set; }

public int Length { get; }

DynamicJsonObject

TBD

Methods

public DynamicJsonObject(IDictionary<string, object> values);

public override IEnumerable<string> GetDynamicMemberNames();

public override bool TryConvert(ConvertBinder binder, out object result);

public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result);

public override bool TryGetMember(GetMemberBinder binder, out object result);

public override bool TrySetIndex(SetIndexBinder binder, object[] indexes, object value);

public override bool TrySetMember(SetMemberBinder binder, object value);

Facebook (TK)

Renders various flavors of a Facebook "Like" button, optionally for a specified URL.

Methods

public static IHtmlString LikeButton(
[Optional, DefaultParameterValue(
null)] string url,
[Optional, DefaultParameterValue(
"like")] string action,
[Optional, DefaultParameterValue(450)]
int width,
[Optional, DefaultParameterValue(
"standard")] string layout,
[Optional, DefaultParameterValue(
true)] bool showFaces,
[Optional, DefaultParameterValue(
"light")] string colorScheme);

FileUpload (TK)

Renders markup that lets users upload one or multiple files.

Methods

public static HtmlString GetHtml(
[Optional, DefaultParameterValue(1)]
int initialNumberOfFiles,
[Optional, DefaultParameterValue(
true)] bool allowMoreFilesToBeAdded,
[Optional, DefaultParameterValue(
true)] bool includeFormTag,
[Optional, DefaultParameterValue(
null)] string addText,
[Optional, DefaultParameterValue(
null)] string uploadText);

GamerCard (TK)

Renders the specified Xbox gamer tag

Methods

public static HtmlString GetHtml(string gamerTag);

Gravatar (TK)

Renders the Gravatar image for the specified user.

Methods

public static HtmlString GetHtml(
string
email,
[Optional, DefaultParameterValue(80)]
int imageSize,
[Optional, DefaultParameterValue(
null)] string defaultImage,
[Optional, DefaultParameterValue(0)]
GravatarRating rating,
[Optional, DefaultParameterValue(
null)] string imageExtension,
[Optional, DefaultParameterValue(
null)] object attributes);

public static string GetUrl(
string
email,
[Optional, DefaultParameterValue(80)]
int imageSize,
[Optional, DefaultParameterValue(
null)] string defaultImage,
[Optional, DefaultParameterValue(0)]
GravatarRating rating,
[Optional, DefaultParameterValue(
null)] string imageExtension);

GravatarRating (TK)
(enum)

Defines allowed rating values for the Gravatar helper.

 

Default,
G,
PG,
R,
X

HttpAntiForgeryException

Defines an exception that can be thrown by the AntiForgery helper. (Not really so helpful to users, but it's a public API.)

Methods

public HttpAntiForgeryException();

public HttpAntiForgeryException(string message);

public HttpAntiForgeryException(string message, Exception innerException);

Json

Converts data to and from JSON format.

Methods

static Json();

[return: Dynamic]
public static object Decode(string value);

public static T Decode<T>(string value);

[return: Dynamic]
public static object Decode(string value, Type targetType);

public static string Encode(object value);

[return: Dynamic]
public static void Write(object value, TextWriter writer);

LinkShare (TK)

Renders flair buttons that link to social bookmarking sites like Delicious, Digg, Reddit, Twitter, etc. Requires that the user be registered with the social networking site.

Methods

static LinkShare();

public static IHtmlString GetHtml(
string pageTitle,
[Optional, DefaultParameterValue(
null)] string pageLinkBack,
[Optional, DefaultParameterValue(
null)] string twitterUserName,
[Optional, DefaultParameterValue(
null)] string additionalTweetText,
params LinkShareSite[] linkSites);

 

Properties

public static string BitlyApiKey { get; set; }

public static string BitlyLogin { get; set; }

LinkShareSite (TK)
(enum)

Defines allowed values for the LinkShare helper.

 

Delicious,
Digg,
GoogleBuzz,
Facebook,
Reddit,
StumbleUpon,
Twitter,
All

ObjectInfo

Renders an object's properties and values. Used for debugging.

Methods

public static HelperResult Print(
object
value,
[Optional, DefaultParameterValue(10)]
int depth,
[Optional, DefaultParameterValue(0x3e8)]
int enumerationLength);

PreApplicationStartCode (TK)

Provides expanded support for application startup in ASP.NET MVC. See Quick Overview of What Have Changes in ASP.NET MVC 3.

Methods

public static void Start();

ReCaptcha (TK)

Renders a reCAPTCHA box and uses the reCAPTCHA service to verify the user's entry. Requires registration with reCAPTCHA.

Methods

static ReCaptcha();

public static IHtmlString GetHtml(
[Optional, DefaultParameterValue(
null)] string publicKey,
[Optional, DefaultParameterValue(
"red")] string theme,
[Optional, DefaultParameterValue(
"en")] string language,
[Optional, DefaultParameterValue(0)]
int tabIndex);

public static IHtmlString GetHtmlWithOptions(
[Optional, DefaultParameterValue(
null)] string publicKey,
[Optional, DefaultParameterValue(
null)] object options);

public static bool Validate([Optional, DefaultParameterValue(null)] string privateKey);

 

Properties

public static string PrivateKey { get; set; }

public static string PublicKey { get; set; }

ServerInfo

Renders status information about the server and the current request. Used for debugging.

Methods

static ServerInfo();

public static HtmlString GetHtml();

SortDirection
(enum)

Defines allowed values for the WebGrid helper.

 

Ascending,
Descending

StringExtensions [3]

Provides methods to convert strings to other data types (AsBool, AsFloat, etc.) or to test whether strings can be converted to other types (IsInt, IsFloat, etc.)

Methods

public static TValue As<TValue>(this string value);

public static TValue As<TValue>(this string value, TValue defaultValue);

public static bool AsBool(this string value);

public static bool AsBool(this string value, bool defaultValue);

public static DateTime AsDateTime(this string value);

public static DateTime AsDateTime(this string value, DateTime defaultValue);

public static decimal AsDecimal(this string value);

public static decimal AsDecimal(this string value, decimal defaultValue);

public static float AsFloat(this string value);

public static float AsFloat(this string value, float defaultValue);

public static int AsInt(this string value);

public static int AsInt(this string value, int defaultValue);

public static bool Is<TValue>(this string value);

public static bool IsBool(this string value);

public static bool IsDateTime(this string value);

public static bool IsDecimal(this string value);

public static bool IsEmpty(this string value);

public static bool IsFloat(this string value);

public static bool IsInt(this string value);

Themes (TK)

Provides support for ASP.NET themes in Razor pages. See Working with Themes in WebMatrix.


Methods

static Themes();

public static string GetResourcePath(string fileName);

public static string GetResourcePath(string folder, string fileName);

public static void Initialize(string themeDirectory, string defaultTheme);

 

Properties

public static ReadOnlyCollection<string> AvailableThemes { get; }

public static string CurrentTheme { get; set; }

public static string DefaultTheme { get; private set; }

public static string ThemeDirectory { get; private set; }

Twitter (TK)

Renders a Twitter feed for the specified user or search term.

Methods

public static HtmlString Profile(
string twitterUserName,
[Optional, DefaultParameterValue(250)]
int width,
[Optional, DefaultParameterValue(300)]
int height,
[Optional, DefaultParameterValue(
"#333333")] string backgroundShellColor,
[Optional, DefaultParameterValue(
"#ffffff")] string shellColor,
[Optional, DefaultParameterValue(
"#000000")] string tweetsBackgroundColor,
[Optional, DefaultParameterValue(
"#ffffff")] string tweetsColor,
[Optional, DefaultParameterValue(
"#4aed05")] string tweetsLinksColor,
[Optional, DefaultParameterValue(4)]
int numberOfTweets,
[Optional, DefaultParameterValue(
false)] bool scrollBar,
[Optional, DefaultParameterValue(
false)] bool loop,
[Optional, DefaultParameterValue(
false)] bool live,
[Optional, DefaultParameterValue(
true)] bool hashTags,
[Optional, DefaultParameterValue(
true)] bool timestamp,
[Optional, DefaultParameterValue(
false)] bool avatars,
[Optional, DefaultParameterValue(
"all")] string behavior,
[Optional, DefaultParameterValue(0x1770)]
int searchInterval);

public static IHtmlString Search(
string searchQuery,
[Optional, DefaultParameterValue(250)]
int width,
[Optional, DefaultParameterValue(300)]
int height,
[Optional, DefaultParameterValue(
null)] string title,
[Optional, DefaultParameterValue(
null)] string caption,
[Optional, DefaultParameterValue(
"#8ec1da")] string backgroundShellColor,
[Optional, DefaultParameterValue(
"#ffffff")] string shellColor,
[Optional, DefaultParameterValue(
"#ffffff")] string tweetsBackgroundColor,
[Optional, DefaultParameterValue(
"#444444")] string tweetsColor,
[Optional, DefaultParameterValue(
"#1985b5")] string tweetsLinksColor,
[Optional, DefaultParameterValue(
false)] bool scrollBar,
[Optional, DefaultParameterValue(
true)] bool loop,
[Optional, DefaultParameterValue(
true)] bool live,
[Optional, DefaultParameterValue(
true)] bool hashTags,
[Optional, DefaultParameterValue(
true)] bool timestamp,
[Optional, DefaultParameterValue(
true)] bool avatars,
[Optional, DefaultParameterValue(
"default")] string behavior,
[Optional, DefaultParameterValue(0x1770)]
int searchInterval);

Validation [2]

Disables request validation for an individual field (or all fields) in a page. See ValidateRequest check.

Methods

public static void Exclude(params string[] fields)

public static void ExcludeAll()

internal static void ExcludeAll(HttpContext context)

Video (TK)

Renders a Flash, Windows Media Player, or Silverlight media player.

Methods

static Video();

public static HelperResult Flash(
string path,
[Optional, DefaultParameterValue(
null)] string width,
[Optional, DefaultParameterValue(
null)] string height,
[Optional, DefaultParameterValue(
true)] bool play,
[Optional, DefaultParameterValue(
true)] bool loop,
[Optional, DefaultParameterValue(
true)] bool menu,
[Optional, DefaultParameterValue(
null)] string bgColor,
[Optional, DefaultParameterValue(
null)] string quality,
[Optional, DefaultParameterValue(
null)] string scale,
[Optional, DefaultParameterValue(
null)] string windowMode,
[Optional, DefaultParameterValue(
null)] string baseUrl,
[Optional, DefaultParameterValue(
null)] string version,
[Optional, DefaultParameterValue(
null)] object options,
[Optional, DefaultParameterValue(
null)] object htmlAttributes,
[Optional, DefaultParameterValue(
null)] string embedName);

public static HelperResult MediaPlayer(
string path,
[Optional, DefaultParameterValue(
null)] string width,
[Optional, DefaultParameterValue(
null)] string height,
[Optional, DefaultParameterValue(
true)] bool autoStart,
[Optional, DefaultParameterValue(1)]
int playCount,
[Optional, DefaultParameterValue(
null)] string uiMode,
[Optional, DefaultParameterValue(
false)] bool stretchToFit,
[Optional, DefaultParameterValue(
true)] bool enableContextMenu,
[Optional, DefaultParameterValue(
false)] bool mute,
[Optional, DefaultParameterValue(-1)]
int volume,
[Optional, DefaultParameterValue(
null)] string baseUrl,
[Optional, DefaultParameterValue(
null)] object options,
[Optional, DefaultParameterValue(
null)] object htmlAttributes,
[Optional, DefaultParameterValue(
null)] string embedName);

public static HelperResult Silverlight(
string
path, string width,
string height,
[Optional, DefaultParameterValue(
null)] string bgColor,
[Optional, DefaultParameterValue(
null)] string initParameters,
[Optional, DefaultParameterValue(
null)] string minimumVersion,
[Optional, DefaultParameterValue(
true)] bool autoUpgrade,
[Optional, DefaultParameterValue(
null)] object options,
[Optional, DefaultParameterValue(
null)] object htmlAttributes);

WebCache

Stores and retrieves information in the ASP.NET cache. Used for performance. For background, see Caching Application Data.

Methods

[return: Dynamic]
public static object Get(string key);

[return: Dynamic]
public static object Remove(string key);

public static void Set(
string
key,
object value,
[Optional, DefaultParameterValue(20)]
int minutesToCache,
[Optional, DefaultParameterValue(
true)] bool slidingExpiration);

WebGrid

Displays database data in an HTML table. Optionally supports sorting and paging.

Methods

public WebGrid(
[Dynamic(
new bool[] { false, true })] IEnumerable<object> source,
[Optional, DefaultParameterValue(
null)] IEnumerable<string> columnNames,
[Optional, DefaultParameterValue(
null)] string defaultSort,
[Optional, DefaultParameterValue(10)]
int rowsPerPage,
[Optional, DefaultParameterValue(
true)] bool canPage,
[Optional, DefaultParameterValue(
true)] bool canSort,
[Optional, DefaultParameterValue(
null)] string ajaxUpdateContainerId,
[Optional, DefaultParameterValue(
null)] string fieldNamePrefix,
[Optional, DefaultParameterValue(
null)] string pageFieldName,
[Optional, DefaultParameterValue(
null)] string selectionFieldName,
[Optional, DefaultParameterValue(
null)] string sortFieldName,
[Optional, DefaultParameterValue(
null)] string sortDirectionFieldName);

public WebGridColumn Column(
[Optional, DefaultParameterValue(
null)] string columnName,
[Optional, DefaultParameterValue(
null)] string header,
[Optional, DefaultParameterValue(
null),
   Dynamic(
new bool[] { false, true, false })] Func<object, object> format,
[Optional, DefaultParameterValue(
null)] string style,
[Optional, DefaultParameterValue(
true)] bool canSort);

public WebGridColumn[] Columns(params WebGridColumn[] columnSet);

public IHtmlString GetContainerUpdateScript(string path);

public IHtmlString GetHtml(
[Optional, DefaultParameterValue(
null)] string tableStyle,
[Optional, DefaultParameterValue(
null)] string headerStyle,
[Optional, DefaultParameterValue(
null)] string footerStyle,
[Optional, DefaultParameterValue(
null)] string rowStyle,
[Optional, DefaultParameterValue(
null)] string alternatingRowStyle,
[Optional, DefaultParameterValue(
null)] string selectedRowStyle,
[Optional, DefaultParameterValue(
true)] bool displayHeader,
[Optional, DefaultParameterValue(
false)] bool fillEmptyRows,
[Optional, DefaultParameterValue(
null)] string emptyRowCellValue,
[Optional, DefaultParameterValue(
null)] IEnumerable<WebGridColumn> columns,
[Optional, DefaultParameterValue(
null)] IEnumerable<string> exclusions,
[Optional, DefaultParameterValue(3)]
WebGridPagerModes mode,
[Optional, DefaultParameterValue(
null)] string firstText,
[Optional, DefaultParameterValue(
null)] string previousText,
[Optional, DefaultParameterValue(
null)] string nextText,
[Optional, DefaultParameterValue(
null)] string lastText,
[Optional, DefaultParameterValue(5)]
int numericLinksCount);

public string GetPageUrl(int pageIndex);

public string GetSortUrl(string column);

public HelperResult Pager(
[Optional, DefaultParameterValue(3)]
WebGridPagerModes mode,
[Optional, DefaultParameterValue(
null)] string firstText,
[Optional, DefaultParameterValue(
null)] string previousText,
[Optional, DefaultParameterValue(
null)] string nextText,
[Optional, DefaultParameterValue(
null)] string lastText,
[Optional, DefaultParameterValue(5)]
int numericLinksCount);

public IHtmlString Table(
[Optional, DefaultParameterValue(
null)] string tableStyle,
[Optional, DefaultParameterValue(
null)] string headerStyle,
[Optional, DefaultParameterValue(
null)] string footerStyle,
[Optional, DefaultParameterValue(
null)] string rowStyle,
[Optional, DefaultParameterValue(
null)] string alternatingRowStyle,
[Optional, DefaultParameterValue(
null)] string selectedRowStyle,
[Optional, DefaultParameterValue(
true)] bool displayHeader,
[Optional, DefaultParameterValue(
false)] bool fillEmptyRows,
[Optional, DefaultParameterValue(
null)] string emptyRowCellValue,
[Optional, DefaultParameterValue(
null)] IEnumerable<WebGridColumn> columns,
[Optional, DefaultParameterValue(
null)] IEnumerable<string> exclusions,
[Optional, DefaultParameterValue(
null), Dynamic(new bool[] { false, true, false })] Func<object, object> footer);

 

Properties

public string AjaxUpdateContainerId { get; }

public IEnumerable<string> ColumnNames { get; }

[Dynamic(new bool[] { false, true })]
public IEnumerable<object> DataSource {
   [
return: Dynamic(new bool[] { false, true })] get;
}

public string FieldNamePrefix { get; }

public bool HasSelection { get; }

public int PageCount { get; }

public string PageFieldName { get; }

public int PageIndex { get; set; }

public IList<WebGridRow> Rows { get; }

public int RowsPerPage { get; }

public int SelectedIndex { get; set; }

public WebGridRow SelectedRow { get; }

public string SelectionFieldName { get; }

public string SortColumn { get; set; }

public SortDirection SortDirection { get; set; }

public string SortDirectionFieldName { get; }

public string SortFieldName { get; }

public int TotalRowCount { get; }

WebGridColumn

Defines a single column in a WebGrid object.

Methods

public WebGridColumn();

 

Properties

public bool CanSort

public string ColumnName

[Dynamic(new bool[] { false, true, false })]
public Func<object, object> Format {
   [
return: Dynamic(new bool[] { false, true, false })]
   [CompilerGenerated]
get; [param: Dynamic(new bool[] { false, true, false })]
   [CompilerGenerated]
set;
}

public string Header

public string Style; }

[Flags]
WebGridPagerModes

(enum)

Defines allowable values for the WebGrid helper.

 

All = 7,
FirstLast = 4,
NextPrevious = 2,
Numeric = 1

WebGridRow

Defines a single row in a WebGrid object.

Methods

public IEnumerator<object> GetEnumerator();

public IHtmlString GetSelectLink([Optional, DefaultParameterValue(null)] string text);

public string GetSelectUrl();

IEnumerator IEnumerable.GetEnumerator();

public override string ToString();

public override bool TryGetMember(GetMemberBinder binder, out object result);

 

Properties

public object this[string name] { get; }

public object this[int index] { get; }

[Dynamic]
public object Value { [return: Dynamic] get; }

public WebGrid WebGrid { get; }

WebImage

Provides a way to manage images, such as retrieving from a file upload, saving to file, cropping, resizing, flipping, and adding watermarks.

Methods

public WebImage(
Stream imageStream,
[Optional, DefaultParameterValue(
null)] string format);

public WebImage(
string
filePath,
[Optional, DefaultParameterValue(
null)] string format);

public WebImage(
byte
[] content,
[Optional, DefaultParameterValue(
null)] string format);

public WebImage AddImageWatermark(WebImage watermarkImage,
[Optional, DefaultParameterValue(0)]
int width,
[Optional, DefaultParameterValue(0)]
int height,
[Optional, DefaultParameterValue(
"Right")] string horizontalAlign,
[Optional, DefaultParameterValue(
"Bottom")] string verticalAlign,
[Optional, DefaultParameterValue(100)]
int opacity,
[Optional, DefaultParameterValue(5)]
int padding);

public WebImage AddImageWatermark(
string
watermarkImageFilePath,
[Optional, efaultParameterValue(
null)] string format,
[Optional, DefaultParameterValue(0)]
int width,
[Optional, DefaultParameterValue(0)]
int height,
[Optional, DefaultParameterValue(
"Right")] string horizontalAlign,
[Optional, DefaultParameterValue(
"Bottom")] string verticalAlign,
[Optional, DefaultParameterValue(100)]
int opacity,
[Optional, DefaultParameterValue(5)]
int padding);

public WebImage AddTextWatermark(
string
text,
[Optional, DefaultParameterValue(
"Black")] string fontColor,
[Optional, DefaultParameterValue(12)]
int fontSize,
[Optional, DefaultParameterValue(
"Regular")] string fontStyle,
[Optional, DefaultParameterValue(
"Microsoft Sans Serif")] string fontFamily,
[Optional, DefaultParameterValue(
"Right")] string horizontalAlign,
[Optional, DefaultParameterValue(
"Bottom")] string verticalAlign,
[Optional, DefaultParameterValue(100)]
int opacity,
[Optional, DefaultParameterValue(5)]
int padding);

public WebImage Clone();

public WebImage Crop(
[Optional, DefaultParameterValue(0)]
int top,
[Optional, DefaultParameterValue(0)]
int left,
[Optional, DefaultParameterValue(0)]
int bottom,
[Optional, DefaultParameterValue(0)]
int right);

public WebImage FlipHorizontal();

public WebImage FlipVertical();

public byte[] GetBytes(
[Optional, DefaultParameterValue(
null)] string requestedFormat);

public static WebImage GetImageFromRequest(
[Optional, DefaultParameterValue(
null)] string postedFileName);

public WebImage Resize(
int width,
int
height,
[Optional, DefaultParameterValue(
true)] bool preserveAspectRatio,
[Optional, DefaultParameterValue(
false)] bool preventEnlarge);

public WebImage RotateLeft();

public WebImage RotateRight();

public WebImage Save(
[Optional, DefaultParameterValue(
null)] string filePath,
[Optional, DefaultParameterValue(
null)] string imageFormat);

public WebImage Write([Optional, DefaultParameterValue(null)] string requestedFormat);

 

Properties

public string FileName { get; set; }

public int Height { get; }

public string ImageFormat { get; }

public int Width { get; }

WebMail

Sends email messages. Requires access to (and credentials for) an SMTP server.

Methods

static WebMail();

public static void Send(
string to,
string
subject,
string body,
[Optional, DefaultParameterValue(
null)] string from,
[Optional, DefaultParameterValue(
null)] string cc,
[Optional, DefaultParameterValue(
null)] IEnumerable<string> filesToAttach,
[Optional, DefaultParameterValue(
true)] bool isBodyHtml,
[Optional, DefaultParameterValue(
null)] IEnumerable<string> additionalHeaders);

 

Properties

public static bool EnableSsl { get; set; }

public static string From { get; set; }

public static string Password { get; set; }

public static int SmtpPort { get; set; }

public static string SmtpServer { get; set; }

public static bool SmtpUseDefaultCredentials { get; set; }

public static string UserName { get; set; }

WebSecurity [3]

Provides a way to manage security (login verification, etc.) that interacts with ASP.NET membership.

Fields

public static readonly string EnableSimpleMembershipKey;

 

Methods

static WebSecurity();

public static bool ChangePassword(
string
userName,
string currentPassword,
string newPassword);

public static bool ConfirmAccount(string accountConfirmationToken);

public static string CreateAccount(
string userName,
string password,
[Optional, DefaultParameterValue(
false)] bool requireConfirmationToken);

public static string CreateUserAndAccount(
string userName,
string
password,
[Optional, DefaultParameterValue(
null)] object propertyValues,
[Optional, DefaultParameterValue(
false)] bool requireConfirmationToken);

public static string GeneratePasswordResetToken(
string
userName,
[Optional, DefaultParameterValue(0x5a0)]
int tokenExpirationInMinutesFromNow);

public static DateTime GetCreateDate(string userName);

public static DateTime GetLastPasswordFailureDate(string userName);

public static DateTime GetPasswordChangedDate(string userName);

public static int GetPasswordFailuresSinceLastSuccess(string userName);

public static int GetUserId(string userName);

public static int GetUserIdFromPasswordResetToken(string token);

public static void InitializeDatabaseConnection(
string connectionStringName,
string
userTableName,
string userIdColumn,
string
userNameColumn,
bool autoCreateTables);

public static void InitializeDatabaseConnection(
string connectionString,
string
providerName,
string
userTableName,
string userIdColumn,
string userNameColumn,
bool
autoCreateTables);

public static bool IsAccountLockedOut(
string userName,
int
allowedPasswordAttempts,
int intervalInSeconds);

public static bool IsAccountLockedOut(
string userName,
int
allowedPasswordAttempts,
TimeSpan interval);

public static bool IsConfirmed(string userName);

public static bool IsCurrentUser(string userName);

public static bool Login(
string userName,
string
password,
[Optional, DefaultParameterValue(
false)] bool persistCookie);

public static void Logout();

public static void RequireAuthenticatedUser();

public static void RequireRoles(params string[] roles);

public static void RequireUser(int userId);

public static void RequireUser(string userName);

public static bool ResetPassword(
string passwordResetToken,
string
newPassword);

public static bool UserExists(string userName);

 

Properties

public static int CurrentUserId { get; }

public static string CurrentUserName { get; }

public static bool HasUserId { get; }

public static bool IsAuthenticated { get; }

[1] Helper is in the WebMatrix.Data.dll assembly and the WebMatrix.Data namespace.
[2] Helper is in the System.Web.WebPages.dll assembly but is in the System.Web.Helpers namespace.
[3] Helper is in the System.Web.WebPages.dll assembly and System.Web.WebPages namespace.

Notes

The definition of "helper" is actually a bit loose. There is no helper base class (as with Control), and not even any specific functionality that they all have in common, like rendering HTML, which most do, but others (e.g., WebMail) do not. The definition therefore is not so much technical as conventional -- by convention, a helper is a thing that provides an easy way to do something that might otherwise be more complex. For example, WebImage makes it way easier to work with images; it's a good example of a helper. Is Database a helper? Hard to say.

Anyway, I got this information by using Redgate's .NET Reflector. I popped the ASP.NET Web Pages (aka Razor) assemblies into the tool and disassembled the ones that pertained to helpers. I then copied the member signatures into Visual Studio and deleted anything marked internal or private or abstract or interface. Or that involved factory or extension — basically, I extended only slightly the criterion used to create the API Quick Reference on the ASP.NET site. (Therefore, this is not suitable for serious MVC use.) I did some light reformatting in order to make the longer signatures easier to parse. (For humans, I mean.) I got some of the helper descriptions from the API Quick Reference, which I tweaked. Go there for examples of most of these helpers.

Obviously, it would be extremely useful to have descriptions of the members plus examples. (Some examples are provided in the API Quick Reference, as noted.) My hope is that most of the useful members  are pretty much self-explanatory. Given that this is a temporary listing anyway (a proper, MSDN-based API reference will be available in the fullness of time), I probably will not flesh out the details. That said, feel free to contact me with questions; your questions will help us decide where the documentation priorities are.

There's an excellent likelihood that I made errors while copying or cleaning up or formatting. But really, this is just an illustration of something you, too, could do! :-) However, I do apologize if I inadvertently mislead you here about any of these APIs.