ASP.Net C# ResolveClientUrl inside Class

前端 未结 4 1150
我寻月下人不归
我寻月下人不归 2021-02-01 20:36

I have the following code:

public class NavigationPath
{
    private string menuItems = \"
  • \" + \"
  • 4条回答
    •  失恋的感觉
      2021-02-01 21:12

      ResolveClientUrl is a member of the System.Web.UI.Control class, hence it's accessible directly as:

      var url = ResolveClientUrl("~/Some/Url/");
      

      when called within the code of your asp.net page.

      To use it inside a class you're going to have to pass the Page (or a control on the page) into the class in its constructor. Even then I'm not sure you'd be able to use it in the way you've indicated. You'd probably have to do something similar to:

      public class NavigationPath
      {
        private string menuItems = string.Empty;
      
        public NavigationPath(Page page)
        {
          menuItems = "
    • " + "home" + "
    • "; } }

      And then inside your asp.net page do something like:

      var navPath = new NavigationPage(this);
      

    提交回复
    热议问题