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

Microsoft.AspNet.Mvc.Razor.RazorPage.RazorPage()
public RazorPage()

Properties

Context()
Return type:HttpContext
public HttpContext Context { get; }
HtmlEncoder()

Gets the @!:IHtmlEncoder- to be used for encoding HTML.

Return type: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 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; }
RenderBodyDelegate()
Return type:System.Action{System.IO.TextWriter}
public Action<TextWriter> RenderBodyDelegate { 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.ITempDataDictionary]() from the [Microsoft.AspNet.Mvc.Razor.RazorPage.ViewContext](Microsoft.AspNet.Mvc.Razor.RazorPage.yml).

Return type:Microsoft.AspNet.Mvc.ITempDataDictionary
public ITempDataDictionary TempData { get; }
User()
Return type:System.Security.Claims.ClaimsPrincipal
public virtual ClaimsPrincipal User { get; }
ViewBag()
Return type:dynamic
public ViewBag { get; }
ViewContext()
Return type:Microsoft.AspNet.Mvc.ViewContext
public ViewContext ViewContext { get; set; }

Methods

BeginContext(System.Int32, System.Int32, System.Boolean)
Arguments:
  • position (System.Int32) –
  • length (System.Int32) –
  • isLiteral (System.Boolean) –
public void BeginContext(int position, int length, bool isLiteral)
Microsoft.AspNet.Mvc.Razor.RazorPage.CreateTagHelper<TTagHelper>()

Creates and activates a @!:ITagHelper-.

Return type:TTagHelper
Returns:The activated @!: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)](Microsoft.AspNet.Mvc.Razor.RazorPage.yml) or [Microsoft.AspNet.Mvc.Razor.RazorPage.RenderSectionAsync(System.String,System.Boolean)](Microsoft.AspNet.Mvc.Razor.RazorPage.yml).

Arguments:
  • name (System.String) – The name of the section to create.
  • section (Microsoft.AspNet.Mvc.Razor.RenderAsyncDelegate) – The [Microsoft.AspNet.Mvc.Razor.RenderAsyncDelegate](Microsoft.AspNet.Mvc.Razor.RenderAsyncDelegate.yml) to execute when rendering the section.
public void DefineSection(string name, RenderAsyncDelegate section)
Microsoft.AspNet.Mvc.Razor.RazorPage.EndContext()
public void EndContext()
Microsoft.AspNet.Mvc.Razor.RazorPage.EndTagHelperWritingScope()

Ends the current writing scope that was started by calling [Microsoft.AspNet.Mvc.Razor.RazorPage.StartTagHelperWritingScope](Microsoft.AspNet.Mvc.Razor.RazorPage.yml).

Return type:TagHelperContent
Returns:The [System.IO.TextWriter]() that contains the content written to the [Microsoft.AspNet.Mvc.Razor.RazorPage.Output](Microsoft.AspNet.Mvc.Razor.RazorPage.yml) or [Microsoft.AspNet.Mvc.ViewContext.Writer]() during the writing scope.
public TagHelperContent EndTagHelperWritingScope()
Microsoft.AspNet.Mvc.Razor.RazorPage.EnsureRenderedBodyOrSections()
public void EnsureRenderedBodyOrSections()
Microsoft.AspNet.Mvc.Razor.RazorPage.ExecuteAsync()
Return type:System.Threading.Tasks.Task
public abstract Task ExecuteAsync()
Microsoft.AspNet.Mvc.Razor.RazorPage.FlushAsync()

Invokes [System.IO.TextWriter.FlushAsync]() on [Microsoft.AspNet.Mvc.Razor.RazorPage.Output](Microsoft.AspNet.Mvc.Razor.RazorPage.yml) writing out any buffered content to the @!:HttpResponse.Body-.

Return type:System.Threading.Tasks.Task{Microsoft.AspNet.Mvc.Rendering.HtmlString}
Returns:A [System.Threading.Tasks.Task`1]() that represents the asynchronous flush operation and on completion returns a [Microsoft.AspNet.Mvc.Rendering.HtmlString.Empty]().
public Task<HtmlString> FlushAsync()
Href(System.String)
Arguments:
  • contentPath (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 [System.Type]().
  • 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)
Arguments:
  • name (System.String) –
Return type:

System.Boolean

public bool IsSectionDefined(string name)
Microsoft.AspNet.Mvc.Razor.RazorPage.RenderBody()
Return type:Microsoft.AspNet.Mvc.Razor.HelperResult
protected virtual HelperResult RenderBody()
RenderSection(System.String)

In layout pages, renders the content of the section named <paramref name=”name” />.

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

Microsoft.AspNet.Mvc.Rendering.HtmlString

Returns:

Returns [Microsoft.AspNet.Mvc.Rendering.HtmlString.Empty]() to allow the [Microsoft.AspNet.Mvc.Razor.RazorPage.Write(System.Object)](Microsoft.AspNet.Mvc.Razor.RazorPage.yml) call to succeed.

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

In layout pages, renders the content of the section named <paramref name=”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 [Microsoft.AspNet.Mvc.Rendering.HtmlString.Empty]() to allow the [Microsoft.AspNet.Mvc.Razor.RazorPage.Write(System.Object)](Microsoft.AspNet.Mvc.Razor.RazorPage.yml) call to succeed.

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

In layout pages, asynchronously renders the content of the section named <paramref name=”name” />.

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

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

Returns:

A [System.Threading.Tasks.Task`1]() that on completion returns [Microsoft.AspNet.Mvc.Rendering.HtmlString.Empty]() that allows the [Microsoft.AspNet.Mvc.Razor.RazorPage.Write(System.Object)](Microsoft.AspNet.Mvc.Razor.RazorPage.yml) 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 <paramref name=”name” />.

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

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

Returns:

A [System.Threading.Tasks.Task`1]() that on completion returns [Microsoft.AspNet.Mvc.Rendering.HtmlString.Empty]() that allows the [Microsoft.AspNet.Mvc.Razor.RazorPage.Write(System.Object)](Microsoft.AspNet.Mvc.Razor.RazorPage.yml) call to succeed.

public Task<HtmlString> RenderSectionAsync(string name, bool required)
Microsoft.AspNet.Mvc.Razor.RazorPage.SetAntiForgeryCookieAndHeader()

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

Return type:Microsoft.AspNet.Mvc.Rendering.HtmlString
Returns:A [Microsoft.AspNet.Mvc.Rendering.HtmlString]() that returns a [Microsoft.AspNet.Mvc.Rendering.HtmlString.Empty]().
public virtual HtmlString SetAntiForgeryCookieAndHeader()
Microsoft.AspNet.Mvc.Razor.RazorPage.StartTagHelperWritingScope()

Starts a new writing scope.

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

Starts a new writing scope with the given <paramref name=”writer” />.

Arguments:
  • writer (System.IO.TextWriter) –
public void StartTagHelperWritingScope(TextWriter writer)
Write(System.Object)

Writes the specified <paramref name=”value” /> with HTML encoding to [Microsoft.AspNet.Mvc.Razor.RazorPage.Output](Microsoft.AspNet.Mvc.Razor.RazorPage.yml).

Arguments:
  • value (System.Object) – The [System.Object]() to write.
public virtual void Write(object value)
WriteAttribute(System.String, Microsoft.AspNet.Mvc.Razor.PositionTagged<System.String>, Microsoft.AspNet.Mvc.Razor.PositionTagged<System.String>, Microsoft.AspNet.Mvc.Razor.AttributeValue[])
Arguments:
  • name (System.String) –
  • prefix (Microsoft.AspNet.Mvc.Razor.PositionTagged{System.String}) –
  • suffix (Microsoft.AspNet.Mvc.Razor.PositionTagged{System.String}) –
  • values (Microsoft.AspNet.Mvc.Razor.AttributeValue[]) –
public virtual void WriteAttribute(string name, PositionTagged<string> prefix, PositionTagged<string> suffix, params AttributeValue[] values)
WriteAttributeTo(System.IO.TextWriter, System.String, Microsoft.AspNet.Mvc.Razor.PositionTagged<System.String>, Microsoft.AspNet.Mvc.Razor.PositionTagged<System.String>, Microsoft.AspNet.Mvc.Razor.AttributeValue[])
Arguments:
  • writer (System.IO.TextWriter) –
  • name (System.String) –
  • prefix (Microsoft.AspNet.Mvc.Razor.PositionTagged{System.String}) –
  • suffix (Microsoft.AspNet.Mvc.Razor.PositionTagged{System.String}) –
  • values (Microsoft.AspNet.Mvc.Razor.AttributeValue[]) –
public virtual void WriteAttributeTo(TextWriter writer, string name, PositionTagged<string> prefix, PositionTagged<string> suffix, params AttributeValue[] values)
WriteLiteral(System.Object)

Writes the specified <paramref name=”value” /> without HTML encoding to [Microsoft.AspNet.Mvc.Razor.RazorPage.Output](Microsoft.AspNet.Mvc.Razor.RazorPage.yml).

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

Writes the specified <paramref name=”value” /> without HTML encoding to the <paramref name=”writer” />.

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

Writes the specified <paramref name=”value” /> without HTML encoding to [Microsoft.AspNet.Mvc.Razor.RazorPage.Output](Microsoft.AspNet.Mvc.Razor.RazorPage.yml).

Arguments:
  • writer (System.IO.TextWriter) –
  • value (System.String) – The [System.String]() to write.
public virtual void WriteLiteralTo(TextWriter writer, string value)
WriteTagHelperAsync(TagHelperExecutionContext)

Writes the content of a specified <paramref name=”tagHelperExecutionContext” />.

Arguments:
  • tagHelperExecutionContext (TagHelperExecutionContext) – The execution context containing the content.
Return type:

System.Threading.Tasks.Task

Returns:

A [System.Threading.Tasks.Task]() that on completion writes the <paramref name=”tagHelperExecutionContext” /> content.

public Task WriteTagHelperAsync(TagHelperExecutionContext tagHelperExecutionContext)
WriteTagHelperToAsync(System.IO.TextWriter, TagHelperExecutionContext)

Writes the content of a specified <paramref name=”tagHelperExecutionContext” /> to the specified

<paramref name=”writer” />.

Arguments:
  • writer (System.IO.TextWriter) – The [System.IO.TextWriter]() instance to write to.
  • tagHelperExecutionContext (TagHelperExecutionContext) – The execution context containing the content.
Return type:

System.Threading.Tasks.Task

Returns:

A [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, IHtmlEncoder, System.Object, System.Boolean)

Writes the specified <paramref name=”value” /> with HTML encoding to given <paramref name=”writer” />.

Arguments:
  • writer (System.IO.TextWriter) – The [System.IO.TextWriter]() instance to write to.
  • encoder (IHtmlEncoder) – The @!:IHtmlEncoder- to use when encoding <paramref name=”value” />.
  • value (System.Object) – The [System.Object]() to write.
  • escapeQuotes (System.Boolean) – If <c>true</c> escapes double quotes in a <paramref name=”value” /> of type [Microsoft.AspNet.Mvc.Rendering.HtmlString](). Otherwise writes [Microsoft.AspNet.Mvc.Rendering.HtmlString]() values as-is.
public static void WriteTo(TextWriter writer, IHtmlEncoder encoder, object value, bool escapeQuotes)
WriteTo(System.IO.TextWriter, System.Object)

Writes the specified <paramref name=”value” /> with HTML encoding to <paramref name=”writer” />.

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

Writes the specified <paramref name=”value” /> with HTML encoding to <paramref name=”writer” />.

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