开发者

.NET: Accessing static MVC controller method from View

I've got an .aspx page with this in it:

<%@ Import Namespace="System.Web.Mvc" %>
<%= AssetController.ScriptTag("/js/Community/CommunityWizard.js")%>

And I have an AssetController class:

Imports System.Web.Mvc

Public Class AssetController
    Inherits Controller

    Public Shared Function ScriptTag(ByVal src As String) As String
        Return String.Format(
            "<script type='text/javascript' sr开发者_运维问答c='/js.mvc?src={0}&{1}'></script>", 
            System.Web.HttpContext.Current.Server.UrlEncode(src), 
            New BuildVersion().ToString()
        )
    End Function
End Class

The project has a reference added to the 3.0.0.0 version of System.Web.Mvc assembly.

When I try to view the page in a browser, I get a HTTP 500 with this message:

BC30007: Reference required to assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' containing the base class 'System.Web.Mvc.Controller'. Add one to your project.

What gives? I don't understand why I can use this controller everywhere in our ASP.NET Forms/MVC hybrid application, but not in a view.

EDIT: In fact, when I type <% System.Web. into the .aspx view, Mvc doesn't even appear in Intellisense!


Solved. Was missing this in my view:

<%@ Assembly Name="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>


You're probably missing the web.Config that usually goes in your /Views folder.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜