RazorPage Class

Summary

Represents properties and methods that are needed in order to render a view that uses Razor syntax.

Syntax

public abstract class RazorPage : IRazorPage

GitHub

View on GitHub

class Microsoft.AspNet.Mvc.Razor.RazorPage

Constructors

RazorPage()
public RazorPage()

Methods

AddHtmlAttributeValue(System.String, System.Int32, System.Object, System.Int32, System.Int32, System.Boolean)
public void AddHtmlAttributeValue(string prefix, int prefixOffset, object value, int valueOffset, int valueLength, bool isLiteral)
BeginAddHtmlAttributeValues(Microsoft.AspNet.Razor.Runtime.TagHelpers.TagHelperExecutionContext, System.String, System.Int32)
public void BeginAddHtmlAttributeValues(TagHelperExecutionContext executionContext, string attributeName, int attributeValuesCount)
BeginContext(System.Int32, System.Int32, System.Boolean)
public void BeginContext(int position, int length, bool isLiteral)
BeginWriteAttribute(System.String, System.String, System.Int32, System.String, System.Int32, System.Int32)
public virtual void BeginWriteAttribute(string name, string prefix, int prefixOffset, string suffix, int suffixOffset, int attributeValuesCount)
BeginWriteAttributeTo(System.IO.TextWriter, System.String, System.String, System.Int32, System.String, System.Int32, System.Int32)
public virtual void BeginWriteAttributeTo(TextWriter writer, string name, string prefix, int prefixOffset, string suffix, int suffixOffset, int attributeValuesCount)
CreateTagHelper<TTagHelper>()

Creates and activates a Microsoft.AspNet.Razor.TagHelpers.ITagHelper.

Return type:{TTagHelper}
Returns:The activated <see cref=”T:Microsoft.AspNet.Razor.TagHelpers.ITagHelper” />.
public TTagHelper CreateTagHelper<TTagHelper>()where TTagHelper : ITagHelper
DefineSection(System.String, Microsoft.AspNet.Mvc.Razor.RenderAsyncDelegate)

Creates a named content section in the page that can be invoked in a Layout page using Microsoft.AspNet.Mvc.Razor.RazorPage.RenderSection(System.String) or Microsoft.AspNet.Mvc.Razor.RazorPage.RenderSectionAsync(System.String,System.Boolean).

Arguments:
  • name (System.String) – The name of the section to create.
  • section (Microsoft.AspNet.Mvc.Razor.RenderAsyncDelegate) – The to execute when rendering the section.
public void DefineSection(string name, RenderAsyncDelegate section)
EndAddHtmlAttributeValues(Microsoft.AspNet.Razor.Runtime.TagHelpers.TagHelperExecutionContext)
public void EndAddHtmlAttributeValues(TagHelperExecutionContext executionContext)
EndContext()
public void EndContext()
EndTagHelperWritingScope()

Ends the current writing scope that was started by calling Microsoft.AspNet.Mvc.Razor.RazorPage.StartTagHelperWritingScope.

Return type:Microsoft.AspNet.Razor.TagHelpers.TagHelperContent
Returns:The <see cref=”T:System.IO.TextWriter” /> that contains the content written to the <see cref=”P:Microsoft.AspNet.Mvc.Razor.RazorPage.Output” /> or <see cref=”P:Microsoft.AspNet.Mvc.Rendering.ViewContext.Writer” /> during the writing scope.
public TagHelperContent EndTagHelperWritingScope()
EndWriteAttribute()
public virtual void EndWriteAttribute()
EndWriteAttributeTo(System.IO.TextWriter)
public virtual void EndWriteAttributeTo(TextWriter writer)
EnsureRenderedBodyOrSections()
public void EnsureRenderedBodyOrSections()
ExecuteAsync()
Return type:System.Threading.Tasks.Task
public abstract Task ExecuteAsync()
FlushAsync()

Invokes System.IO.TextWriter.FlushAsync on Microsoft.AspNet.Mvc.Razor.RazorPage.Output writing out any buffered content to the Microsoft.AspNet.Http.HttpResponse.Body.

Return type:System.Threading.Tasks.Task{Microsoft.AspNet.Mvc.Rendering.HtmlString}
Returns:A <see cref=”T:System.Threading.Tasks.Task`1” /> that represents the asynchronous flush operation and on completion returns a <see cref=”F:Microsoft.AspNet.Mvc.Rendering.HtmlString.Empty” />.
public Task<HtmlString> FlushAsync()
Href(System.String)
Return type:System.String
public virtual string Href(string contentPath)
InvalidTagHelperIndexerAssignment(System.String, System.String, System.String)

Format an error message about using an indexer when the tag helper property is <c>null</c>.

Arguments:
  • attributeName (System.String) – Name of the HTML attribute associated with the indexer.
  • tagHelperTypeName (System.String) – Full name of the tag helper .
  • propertyName (System.String) – Dictionary property in the tag helper.
Return type:

System.String

Returns:

An error message about using an indexer when the tag helper property is <c>null</c>.

public static string InvalidTagHelperIndexerAssignment(string attributeName, string tagHelperTypeName, string propertyName)
IsSectionDefined(System.String)

Returns a value that indicates whether the specified section is defined in the content page.

Arguments:
  • name (System.String) – The section name to search for.
Return type:

System.Boolean

Returns:

<c>true</c> if the specified section is defined in the content page; otherwise, <c>false</c>.

public bool IsSectionDefined(string name)
RenderBody()

In a Razor layout page, renders the portion of a content page that is not within a named section.

Return type:Microsoft.AspNet.Mvc.Razor.HelperResult
Returns:The HTML content to render.
protected virtual HelperResult RenderBody()
RenderSection(System.String)

In layout pages, renders the content of the section named name.

Arguments:
  • name (System.String) – The name of the section to render.
Return type:

Microsoft.AspNet.Mvc.Rendering.HtmlString

Returns:

Returns <see cref=”F:Microsoft.AspNet.Mvc.Rendering.HtmlString.Empty” /> to allow the <see cref=”M:Microsoft.AspNet.Mvc.Razor.RazorPage.Write(System.Object)” /> call to succeed.

public HtmlString RenderSection(string name)
RenderSection(System.String, System.Boolean)

In layout pages, renders the content of the section named name.

Arguments:
  • name (System.String) – The section to render.
  • required (System.Boolean) – Indicates if this section must be rendered.
Return type:

Microsoft.AspNet.Mvc.Rendering.HtmlString

Returns:

Returns <see cref=”F:Microsoft.AspNet.Mvc.Rendering.HtmlString.Empty” /> to allow the <see cref=”M:Microsoft.AspNet.Mvc.Razor.RazorPage.Write(System.Object)” /> call to succeed.

public HtmlString RenderSection(string name, bool required)
RenderSectionAsync(System.String)

In layout pages, asynchronously renders the content of the section named name.

Arguments:
  • name (System.String) – The section to render.
Return type:

System.Threading.Tasks.Task{Microsoft.AspNet.Mvc.Rendering.HtmlString}

Returns:

A <see cref=”T:System.Threading.Tasks.Task`1” /> that on completion returns <see cref=”F:Microsoft.AspNet.Mvc.Rendering.HtmlString.Empty” /> that allows the <see cref=”M:Microsoft.AspNet.Mvc.Razor.RazorPage.Write(System.Object)” /> call to succeed.

public Task<HtmlString> RenderSectionAsync(string name)
RenderSectionAsync(System.String, System.Boolean)

In layout pages, asynchronously renders the content of the section named name.

Arguments:
  • name (System.String) – The section to render.
Return type:

System.Threading.Tasks.Task{Microsoft.AspNet.Mvc.Rendering.HtmlString}

Returns:

A <see cref=”T:System.Threading.Tasks.Task`1” /> that on completion returns <see cref=”F:Microsoft.AspNet.Mvc.Rendering.HtmlString.Empty” /> that allows the <see cref=”M:Microsoft.AspNet.Mvc.Razor.RazorPage.Write(System.Object)” /> call to succeed.

public Task<HtmlString> RenderSectionAsync(string name, bool required)
SetAntiforgeryCookieAndHeader()

Sets antiforgery cookie and X-Frame-Options header on the response.

Return type:Microsoft.AspNet.Mvc.Rendering.HtmlString
Returns:A <see cref=”T:Microsoft.AspNet.Mvc.Rendering.HtmlString” /> that returns a <see cref=”F:Microsoft.AspNet.Mvc.Rendering.HtmlString.Empty” />.
public virtual HtmlString SetAntiforgeryCookieAndHeader()
StartTagHelperWritingScope()

Starts a new writing scope.

public void StartTagHelperWritingScope()
StartTagHelperWritingScope(System.IO.TextWriter)

Starts a new writing scope with the given writer.

public void StartTagHelperWritingScope(TextWriter writer)
Write(System.Object)

Writes the specified value with HTML encoding to Microsoft.AspNet.Mvc.Razor.RazorPage.Output.

Arguments:
  • value (System.Object) – The to write.
public virtual void Write(object value)
WriteAttributeValue(System.String, System.Int32, System.Object, System.Int32, System.Int32, System.Boolean)
public void WriteAttributeValue(string prefix, int prefixOffset, object value, int valueOffset, int valueLength, bool isLiteral)
WriteAttributeValueTo(System.IO.TextWriter, System.String, System.Int32, System.Object, System.Int32, System.Int32, System.Boolean)
public void WriteAttributeValueTo(TextWriter writer, string prefix, int prefixOffset, object value, int valueOffset, int valueLength, bool isLiteral)
WriteLiteral(System.Object)

Writes the specified value without HTML encoding to Microsoft.AspNet.Mvc.Razor.RazorPage.Output.

Arguments:
  • value (System.Object) – The to write.
public virtual void WriteLiteral(object value)
WriteLiteralTo(System.IO.TextWriter, System.Object)

Writes the specified value without HTML encoding to the writer.

Arguments:
  • writer (System.IO.TextWriter) – The instance to write to.
  • value (System.Object) – The to write.
public virtual void WriteLiteralTo(TextWriter writer, object value)
WriteLiteralTo(System.IO.TextWriter, System.String)

Writes the specified value without HTML encoding to Microsoft.AspNet.Mvc.Razor.RazorPage.Output.

Arguments:
  • writer (System.IO.TextWriter) – The instance to write to.
  • value (System.String) – The to write.
public virtual void WriteLiteralTo(TextWriter writer, string value)
WriteTagHelperAsync(Microsoft.AspNet.Razor.Runtime.TagHelpers.TagHelperExecutionContext)

Writes the content of a specified tagHelperExecutionContext.

Arguments:
  • tagHelperExecutionContext (Microsoft.AspNet.Razor.Runtime.TagHelpers.TagHelperExecutionContext) – The execution context containing the content.
Return type:

System.Threading.Tasks.Task

Returns:

A <see cref=”T:System.Threading.Tasks.Task” /> that on completion writes the <paramref name=”tagHelperExecutionContext” /> content.

public Task WriteTagHelperAsync(TagHelperExecutionContext tagHelperExecutionContext)
WriteTagHelperToAsync(System.IO.TextWriter, Microsoft.AspNet.Razor.Runtime.TagHelpers.TagHelperExecutionContext)

Writes the content of a specified tagHelperExecutionContext to the specified writer.

Arguments:
  • writer (System.IO.TextWriter) – The instance to write to.
  • tagHelperExecutionContext (Microsoft.AspNet.Razor.Runtime.TagHelpers.TagHelperExecutionContext) – The execution context containing the content.
Return type:

System.Threading.Tasks.Task

Returns:

A <see cref=”T:System.Threading.Tasks.Task” /> that on completion writes the <paramref name=”tagHelperExecutionContext” /> content to the <paramref name=”writer” />.

public Task WriteTagHelperToAsync(TextWriter writer, TagHelperExecutionContext tagHelperExecutionContext)
WriteTo(System.IO.TextWriter, Microsoft.Extensions.WebEncoders.IHtmlEncoder, System.Object, System.Boolean)

Writes the specified value with HTML encoding to given writer.

Arguments:
  • writer (System.IO.TextWriter) – The instance to write to.
  • encoder (Microsoft.Extensions.WebEncoders.IHtmlEncoder) – The to use when encoding .
  • value (System.Object) – The to write.
  • escapeQuotes (System.Boolean) – If true escapes double quotes in a of type . Otherwise writes values as-is.
public static void WriteTo(TextWriter writer, IHtmlEncoder encoder, object value, bool escapeQuotes)
WriteTo(System.IO.TextWriter, System.Object)

Writes the specified value with HTML encoding to writer.

Arguments:
  • writer (System.IO.TextWriter) – The instance to write to.
  • value (System.Object) – The to write.
public virtual void WriteTo(TextWriter writer, object value)
WriteTo(System.IO.TextWriter, System.String)

Writes the specified value with HTML encoding to writer.

Arguments:
  • writer (System.IO.TextWriter) – The instance to write to.
  • value (System.String) – The to write.
public virtual void WriteTo(TextWriter writer, string value)

Properties

Context()

An Microsoft.AspNet.Http.HttpContext representing the current request execution.

Return type:Microsoft.AspNet.Http.HttpContext
public HttpContext Context { get; }
HtmlEncoder()

Gets the Microsoft.Extensions.WebEncoders.IHtmlEncoder to be used for encoding HTML.

Return type:Microsoft.Extensions.WebEncoders.IHtmlEncoder
public IHtmlEncoder HtmlEncoder { get; set; }
IsLayoutBeingRendered()
Return type:System.Boolean
public bool IsLayoutBeingRendered { get; set; }
IsPartial()
Return type:System.Boolean
public bool IsPartial { get; set; }
Layout()
Return type:System.String
public string Layout { get; set; }
Output()

Gets the System.IO.TextWriter that the page is writing output to.

Return type:System.IO.TextWriter
public virtual TextWriter Output { get; }
PageExecutionContext()
Return type:Microsoft.AspNet.PageExecutionInstrumentation.IPageExecutionContext
public IPageExecutionContext PageExecutionContext { get; set; }
Path()
Return type:System.String
public string Path { get; set; }
PreviousSectionWriters()
Return type:System.Collections.Generic.IDictionary{System.String,Microsoft.AspNet.Mvc.Razor.RenderAsyncDelegate}
public IDictionary<string, RenderAsyncDelegate> PreviousSectionWriters { get; set; }
RenderBodyDelegateAsync()
Return type:System.Func{System.IO.TextWriter,System.Threading.Tasks.Task}
public Func<TextWriter, Task> RenderBodyDelegateAsync { get; set; }
SectionWriters()
Return type:System.Collections.Generic.IDictionary{System.String,Microsoft.AspNet.Mvc.Razor.RenderAsyncDelegate}
public IDictionary<string, RenderAsyncDelegate> SectionWriters { get; }
TempData()

Gets the Microsoft.AspNet.Mvc.ViewFeatures.ITempDataDictionary from the Microsoft.AspNet.Mvc.Razor.RazorPage.ViewContext.

Return type:Microsoft.AspNet.Mvc.ViewFeatures.ITempDataDictionary
public ITempDataDictionary TempData { get; }
User()

Gets the System.Security.Claims.ClaimsPrincipal of the current logged in user.

Return type:System.Security.Claims.ClaimsPrincipal
public virtual ClaimsPrincipal User { get; }
ViewBag()

Gets the dynamic view data dictionary.

Return type:System.Object
public dynamic ViewBag { get; }
ViewContext()
Return type:Microsoft.AspNet.Mvc.Rendering.ViewContext
public ViewContext ViewContext { get; set; }