Controller.View Method

 

Creates a ViewResult object that renders a view to the response.

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

Overload List

Name Description
System_CAPS_protmethod View()

Creates a ViewResult object that renders a view to the response.

System_CAPS_protmethod View(IView)

Creates a ViewResult object that renders the specified IView object.

System_CAPS_protmethod View(IView, Object)

Creates a ViewResult object that renders the specified IView object.

System_CAPS_protmethod View(Object)

Creates a ViewResult object by using the model that renders a view to the response.

System_CAPS_protmethod View(String)

Creates a ViewResult object by using the view name that renders a view.

System_CAPS_protmethod View(String, Object)

Creates a ViewResult object that renders the specified IView object.

System_CAPS_protmethod View(String, String)

Creates a ViewResult object using the view name and master-page name that renders a view to the response.

System_CAPS_protmethod View(String, String, Object)

Creates a ViewResult object using the view name, master-page name, and model that renders a view.

See Also

Controller Class
System.Web.Mvc Namespace

Return to top

Controller.View Method ()

Creates a ViewResult object that renders a view to the response.

Syntax

protected internal ViewResult View()
public protected:
ViewResult^ View()
member View : unit -> ViewResult
Protected Friend Function View As ViewResult

Return Value

Type: System.Web.Mvc.ViewResult

The View result that renders a view to the response.

Remarks

This method overload of the View class returns a ViewResult object that has an empty ViewName property. If you are writing unit tests for controller actions, take into account the empty ViewName property for unit tests that do not take a string view name.

At run time, if the ViewName property is empty, the current action name is used in place of the ViewName property.

Return to top

Controller.View Method (IView)

Creates a ViewResult object that renders the specified IView object.

Syntax

protected internal ViewResult View(
    IView view
)
public protected:
ViewResult^ View(
    IView^ view
)
member View : 
        view:IView -> ViewResult
Protected Friend Function View (
    view As IView
) As ViewResult

Parameters

Return Value

Type: System.Web.Mvc.ViewResult

The view result.

Remarks

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

Return to top

Controller.View Method (IView, Object)

Creates a ViewResult object that renders the specified IView object.

Syntax

protected internal virtual ViewResult View(
    IView view,
    object model
)
public protected:
virtual ViewResult^ View(
    IView^ view,
    Object^ model
)
abstract View : 
        view:IView *
        model:Object -> ViewResult
override View : 
        view:IView *
        model:Object -> ViewResult
Protected Friend Overridable Function View (
    view As IView,
    model As Object
) As ViewResult

Parameters

  • model
    Type: System.Object

    The model that is rendered by the view.

Return Value

Type: System.Web.Mvc.ViewResult

The view result.

Remarks

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

Return to top

Controller.View Method (Object)

Creates a ViewResult object by using the model that renders a view to the response.

Syntax

protected internal ViewResult View(
    object model
)
public protected:
ViewResult^ View(
    Object^ model
)
member View : 
        model:Object -> ViewResult
Protected Friend Function View (
    model As Object
) As ViewResult

Parameters

  • model
    Type: System.Object

    The model that is rendered by the view.

Return Value

Type: System.Web.Mvc.ViewResult

The view result.

Remarks

This overload of the View method returns a ViewResult object that has an empty ViewName property. If you are writing unit tests for controller actions, take into account the empty ViewNameproperty for unit tests that do not take a string view name.

Return to top

Controller.View Method (String)

Creates a ViewResult object by using the view name that renders a view.

Syntax

protected internal ViewResult View(
    string viewName
)
public protected:
ViewResult^ View(
    String^ viewName
)
member View : 
        viewName:string -> ViewResult
Protected Friend Function View (
    viewName As String
) As ViewResult

Parameters

  • viewName
    Type: System.String

    The name of the view that is rendered to the response.

Return Value

Type: System.Web.Mvc.ViewResult

The view result.

Remarks

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

Return to top

Controller.View Method (String, Object)

Creates a ViewResult object that renders the specified IView object.

Syntax

protected internal ViewResult View(
    string viewName,
    object model
)
public protected:
ViewResult^ View(
    String^ viewName,
    Object^ model
)
member View : 
        viewName:string *
        model:Object -> ViewResult
Protected Friend Function View (
    viewName As String,
    model As Object
) As ViewResult

Parameters

  • viewName
    Type: System.String

    The view that is rendered to the response.

  • model
    Type: System.Object

    The model that is rendered by the view.

Return Value

Type: System.Web.Mvc.ViewResult

The view result.

Remarks

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

Return to top

Controller.View Method (String, String)

Creates a ViewResult object using the view name and master-page name that renders a view to the response.

Syntax

protected internal ViewResult View(
    string viewName,
    string masterName
)
public protected:
ViewResult^ View(
    String^ viewName,
    String^ masterName
)
member View : 
        viewName:string *
        masterName:string -> ViewResult
Protected Friend Function View (
    viewName As String,
    masterName As String
) As ViewResult

Parameters

  • viewName
    Type: System.String

    The name of the view that is rendered to the response.

  • masterName
    Type: System.String

    The name of the master page or template to use when the view is rendered.

Return Value

Type: System.Web.Mvc.ViewResult

The view result.

Remarks

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

Return to top

Controller.View Method (String, String, Object)

Creates a ViewResult object using the view name, master-page name, and model that renders a view.

Syntax

protected internal virtual ViewResult View(
    string viewName,
    string masterName,
    object model
)
public protected:
virtual ViewResult^ View(
    String^ viewName,
    String^ masterName,
    Object^ model
)
abstract View : 
        viewName:string *
        masterName:string *
        model:Object -> ViewResult
override View : 
        viewName:string *
        masterName:string *
        model:Object -> ViewResult
Protected Friend Overridable Function View (
    viewName As String,
    masterName As String,
    model As Object
) As ViewResult

Parameters

  • viewName
    Type: System.String

    The name of the view that is rendered to the response.

  • masterName
    Type: System.String

    The name of the master page or template to use when the view is rendered.

  • model
    Type: System.Object

    The model that is rendered by the view.

Return Value

Type: System.Web.Mvc.ViewResult

The view result.

Remarks

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

Return to top