Hi,
My viewpage doesn't have a codebehind, so how do I tell it to use a strongly typed viewdata?
Hi,
My viewpage doesn't have a codebehind, so how do I tell it to use a strongly typed viewdata?
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.
You can of course create a strongly typed viewdata by inheriting from it and adding a .cs file like this:
Modify the aspx file to inherit from it:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="MyNamespace.MyViewPage" %>