0

Inside a view I'm trying to use variable created from my own class,

My class code :

public class STG_Route
{
    public const string INDEX = "STG";
    public const string ADD = "STG/Add";
    public const string SHOW = "STG/Show";
    public const string PROFILE = "STG/{CODE}";
}

My view code :

    @{ 
    MyNameSpace.BL.TXT_and_ROUTE.Route.STG_Route Route = new MyNameSpace.BL.TXT_and_ROUTE.Route.STG_Route();
}

<td><a href="/Admin/@Route.INDEX"><button type="button" class="btn bg-blue btn-block btn-sm waves-effect">xxx</button></a></td>

But this gave me errors, please any help?

1
  • What errors did it give you? You need to include that information in the question, without us needing to prompt you to provide it. Commented Jun 11, 2020 at 13:41

1 Answer 1

1

Constants by definition are not instance members. Constants are accessed directly from the class.

Add a using statement to the top of the View.

@using MyNameSpace.BL.TXT_and_ROUTE.Route

Then access the constant directly from the STG_Route class. I hope you don;t mind that I took the liberty of fixing the invalid HTML.

<a href="/Admin/@STG_Route.INDEX" class="btn bg-blue btn-block btn-sm waves-effect">xxx</a>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.