MSDN Library

Controller.Content Method (String, String, Encoding)

Creates a content result using a string, the content type, and content encoding.

Namespace:  System.Web.Mvc
Assembly:  System.Web.Mvc (in System.Web.Mvc.dll)

Protected Friend Overridable Function Content ( _
	content As String, _
	contentType As String, _
	contentEncoding As Encoding _
) As ContentResult
Dim content As String
Dim contentType As String
Dim contentEncoding As Encoding
Dim returnValue As ContentResult

returnValue = Me.Content(content, _
	contentType, contentEncoding)


Type: System.String
The content to write to the response.
Type: System.String
The content type (MIME type).
Type: System.Text.Encoding
The content encoding.

Return Value

Type: System.Web.Mvc.ContentResult
The content result instance.

The result object that is prepared by this method is written to the response by the MVC framework when the object is executed.

The example in this section shows how to use markup and code to display "Use <b> for bold text" in the browser when the Test Content link is clicked.

The following example shows markup that invokes the TestContent method.

<%= Html.ActionLink("Test Content Type Encoding", 
        new { id = false, sMsg= "Use <b> for bold text"})%>

The following example shows the TestContent method.

<ValidateInput(False)> _ 
Public Function TstContentTypeEncoding(ByVal id As Boolean, ByVal sMsg As String) As ActionResult 
    Dim contentType As String = "text/plain" 
    If id = False Then 
        contentType = "text/html" 
    End If 
    Return Content(Server.HtmlEncode(sMsg), contentType, System.Text.Encoding.UTF8) 
End Function 

Community Additions

© 2016 Microsoft