C# MVC - 在视图中调用外部类
我认为需要使用外部静态内容提供。 这就是我尝试访问它的方式:
<%@ 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();
%>
但由于某种原因我不能这样做。如何在视图中访问外部类?
(在第一行我使用这个:NameSpace.ActionsMetadata.BrokerAction
用户数据)
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 )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
视图确实没有直接访问此全局状态的业务 - 这应该是控制器的责任。如果控制器访问此数据并将其放入 ViewBag 中以供视图使用,则更符合 MVC 范例。
编辑:
对于 MVC 2,代码将略有不同:
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..
EDIT:
For MVC 2 the code will be slightly different: