开发者

How to inherit from a library in a MVC.NET view

I am trying to implement CKFinder开发者_Python百科 in my MVC.Net website, but the default setup only works for regular asp.net websites, so I am trying to alter it to work.

One page inherits from a library CKFinder.Connector.Connector. In the old days my aspx would just inherit="CKFinder.Connector.Connector", but how is this done in MVC.NET?

Is Inherits="System.Web.Mvc.ViewPage<CKFinder.Connector.Connector>" the same?


If this namespace is used frequently, you should probably consider adding it to the namespaces node in your Views/Web.config file.

This ensures that all pages will have access to this namespace, and intellisense will be available also. This has also been discussed in another question.

The XML structure would be as follows.

<configuration>
  <system.web>
    <pages>
      <namespaces>
        <add namespace="CKFinder.Connector.Connector" /> <!-- <<< Your entry here  -->
      </namespaces>
    </pages>  
  </system.web>
</configuration>

The namespaces node may not exist, so you should add it inside the pages node (which should exist).


Inherits="System.Web.Mvc.ViewPage<CKFinder.Connector.Connector>" would set up CKFinder.Connector.Connector as the strongly-typed Model object for your View page. This would work for you if you're trying to access properties on a Connector instance in your markup using the <%= Model.SomePropertyOnConnectorObject %> syntax.

If instead you need to reference CKFinder.Connector.Connector as a namespace, you would need to add the following line below the page directives and before any markup:

<%@ Import Namespace="CKFinder.Connector.Connector" %>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜