In asp.net mvc, where do I put my strongly typed viewdata link into my view page?
2 answers
Just in the title:
<%@ 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 %>
The Model property is automatically added to your type.
+8
a source to share
You can of course create strongly typed views by inheriting from it and adding the .cs file like this:
- Create a .cs file (for example: if you have "Index.aspx", name it "Index.cs") next to your view.
- Create a class that inherits from the System.Web.Mvc.ViewPage class
-
Modify the aspx file to inherit it:
<% @ Page Title = "Language =" C # "MasterPageFile =" ~ / Views / Shared / Site.Master "Inherits =" MyNamespace.MyViewPage "%>
+1
a source to share