ASP.NET 网页 - 帮手


Web Helpers 极大地简化了 Web 开发和常见编程任务。


ASP.NET 助手

ASP.NET 帮助程序是可以通过单行 Razor 代码访问的组件。

您可以使用存储为 .cshtml 文件的 Razor 语法构建自己的帮助程序,或使用内置的 ASP.NET 帮助程序。

您将在本教程的后续章节中学习如何使用 Razor 助手。

下面是一些有用的 Razor 助手的简短描述:


WebGrid 助手

WebGrid 帮助程序简化了显示数据的方式:

  • 自动设置 HTML 表格来显示数据
  • 支持不同的格式化选项
  • 支持通过数据分页(第一、下、上、最后)
  • 支持通过点击列标题进行排序

图表助手

"Chart Helper" 可以显示具有多种格式选项和标签的不同类型的图表图片。

chart chart

图表助手可以显示数组、数据库或文件中的数据。


网络邮件助手

WebMail 帮助程序提供使用 SMTP(简单邮件传输协议)发送电子邮件的功能。


网页图片助手

WebImage 帮助程序提供了管理网页中图片的功能。

关键字:翻转、旋转、调整大小、水印。



第三方助手

借助 Razor,您可以利用内置或第三方帮助程序来简化电子邮件、数据库、多媒体和社交网络的使用以及导航和 Web 安全等许多其他问题。


分析(谷歌)

Helper Description
Analytics.GetGoogleHtml(webPropertyId) Renders the Google Analytics JavaScript code for the specified ID.
Analytics.GetStatCounterHtml(project, security) Renders the StatCounter Analytics JavaScript code for the specified project.
Analytics.GetYahooHtml(account) Renders the Yahoo Analytics JavaScript code for the specified account.

必应

Helper Description
Bing.SearchBox([boxWidth]) Passes a search to Bing. To specify the site to search and a title for the search box, you can set the Bing.SiteUrl and Bing.SiteTitle properties. Normally you set these properties in the _AppStart page.
Bing.AdvancedSearchBox([, boxWidth] [, resultWidth] [, resultHeight]
  [, themeColor] [, locale]
)
Displays Bing search results in the page with optional formatting. To specify the site to search and a title for the search box, you can set the Bing.SiteUrl and Bing.SiteTitle properties. Normally you set these properties in the _AppStart page.

加密货币

Helper Description
Crypto.Hash(string [, algorithm])
Crypto.Hash(bytes [, algorithm])
Returns a hash for the specified data. The default algorithm is sha256.

Facebook

Helper Description
Facebook.LikeButton(href [, buttonLayout] [, showFaces] [, width] [, height]
[, action] [, font] [, colorScheme] [, refLabel]
)
Lets Facebook users make a connection to pages.

上传文件

Helper Description
FileUpload.GetHtml([initialNumberOfFiles] [, allowMoreFilesToBeAdded]
  [
, includeFormTag] [, addText] [, uploadText])
Renders UI for uploading files.

玩家卡

Helper Description
GamerCard.GetHtml(gamerTag) Renders the specified Xbox gamer tag.

Gravatar 对象参考

Helper Description
Gravatar.GetHtml(email [, imageSize] [, defaultImage] [, rating]
  [, imageExtension] [, attributes]
)
Renders the Gravatar image for the specified email address.

杰森

Helper Description
Json.Encode(object) Converts a data object to a string in the JavaScript Object Notation (JSON) format.
Json.Decode(string) Converts a JSON-encoded input string to a data object that you can iterate over or insert into a database.

联享

Helper Description
LinkShare.GetHtml(pageTitle [, pageLinkBack] [, twitterUserName]
  [, additionalTweetText] [, linkSites]
)
Renders social networking links using the specified title and optional URL.

模型状态

Helper Description
ModelStateDictionary.AddError(key, errorMessage) Associates an error message with a form field. Use the ModelState helper to access this member.
ModelStateDictionary.AddFormError(errorMessage) Associates an error message with a form. Use the ModelState helper to access this member.
ModelStateDictionary.IsValid Returns true if there are no validation errors. Use the ModelState helper to access this member.

对象信息

Helper Description
ObjectInfo.Print(value [, depth] [, enumerationLength]) Renders the properties and values of an object and any child objects.

验证码

Helper Description
Recaptcha.GetHtml([, publicKey] [, theme] [, language] [, tabIndex]) Renders the reCAPTCHA verification test.
ReCaptcha.PublicKey
ReCaptcha.PrivateKey
Sets public and private keys for the reCAPTCHA service. Normally you set these properties in the _AppStart page.
ReCaptcha.Validate([, privateKey]) Returns the result of the reCAPTCHA test.

服务器信息

Helper Description
ServerInfo.GetHtml() Renders status information about ASP.NET Web Pages.

推特

Helper Description
Twitter.Profile(twitterUserName) Renders a Twitter stream for the specified user.
Twitter.Search(searchQuery) Renders a Twitter stream for the specified search text.

视频

Helper Description
Video.Flash(filename [, width, height]) Renders a Flash video player for the specified file with optional width and height.
Video.MediaPlayer(filename [, width, height]) Renders a Windows Media player for the specified file with optional width and height.
Video.Silverlight(filename, width, height) Renders a Silverlight player for the specified .xap file with required width and height.

网络缓存

Helper Description
WebCache.Get(key) Returns the object specified by key, or null if the object is not found.
WebCache.Remove(key) Removes the object specified by key from the cache.
WebCache.Set(key, value [, minutesToCache] [, slidingExpiration]) Puts value into the cache under the name specified by key.

网页图片

Helper Description
WebImage(path) Loads an image from the specified path.
WebImage.AddImagesWatermark(image) Adds the specified image as a watermark.
WebImage.AddTextWatermark(text) Adds the specified text to the image.
WebImage.FlipHorizontal()
WebImage.FlipVertical()
Flips the image horizontally or vertically.
WebImage.GetImageFromRequest() Loads an image when an image is posted to a page during a file upload.
WebImage.Resize(width, height) Resizes the image.
WebImage.RotateLeft()
WebImage.RotateRight()
Rotates the image to the left or the right.
WebImage.Save(path [, imageFormat]) Saves the image to the specified path.