Reputation: 11165
I have a view that that nedds to use an external static content provide. this is how I try to access it:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<NameSpace.ActionsMetadata.BrokerAction>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<%
OpenDemoAccount content = NameSpace.Models.ActionsMetadata.Translations.ContentGroupsHolder();
%>
But I can't this way for some reason. How do I access the external class within the view?
(in the first line I am using this: NameSpace.ActionsMetadata.BrokerAction
user data )
Upvotes: 0
Views: 1135
Reputation: 9017
The view really has no business accessing this global state directly - this should be the responsibility of the Controller. It would be more in line with the MVC paradigm if the Controller accessed this data, and put it in the ViewBag for the view to utilize..
// In controller...
ViewBag.OpenDemoAccount = NameSpace.Models.ActionsMetadata.Translations.ContentsGroupHolder();
// In view...
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<%
OpenDemoAccount content = ViewBag.OpenDemoAccount;
%>
EDIT:
For MVC 2 the code will be slightly different:
// In controller...
ViewData["OpenDemoAccount"] = NameSpace.Models.ActionsMetadata.Translations.ContentsGroupHolder();
// In view...
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<%
OpenDemoAccount content = (OpenDemoAccount)ViewData["OpenDemoAccount"];
%>
Upvotes: 1