John Ohara
John Ohara

Reputation: 2901

c# using embedded code block - can it be made simpler?

I'm using WebForms c#.

I have a few primary site links that I use everywhere - on menus, inline in text etc. I came up with the idea of trying to clean things up a bit as putting a hyperlink control in the middle of busy text is a pain to manage.

I came up with the idea of embedded codeblocks - they may be yesterdays technology, but they provide a simple way of getting simple bits of data into code.

I use routing and already have static methods to pull back routes. I also use enum to store route names.

All is good but in order to embed the method, I need to use the fully qualified name. I can circumvent that by adding a method to my basecontrol class, like this:

    protected string Link(RouteName name, string text)
    {
        return PageRoute.Link(name, text);
    }

Which gives me this:

<% =Link(MySite.BLL.Routing.RouteName.Privacy, "privacy policy") %>

However, I can't get rid of the fully qualified enum that sits in the same namespace as PageRoute.

Is there any way to achieve this, or perhaps another dierction I might take?

This is what I'd like to be able to do:

<% =Link(RouteName.Privacy, "privacy policy") %>

Upvotes: 1

Views: 480

Answers (1)

Magnus
Magnus

Reputation: 46937

You should be able to import the namespace in the aspx page.

<%@ Import namespace="MySite.BLL.Routing" %>

Upvotes: 1

Related Questions