Asp – In asp.net mvc, where do I put the strongly typed viewdata reference in the viewpage

asp.net-mvcviewdata

My viewpage doesn't have a codebehind, so how do I tell it to use a strongly typed viewdata?

Best Answer

Just in header:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" 
            Inherits="System.Web.Mvc.ViewPage<HomePageViewModel>" %>

Then you can access your strongly typed model like this:

<%= Model.Username %>

"Model" property is automatically cast to your type.