More in this section

Forums / Developing with Sitefinity / Get Object View By its Name

Get Object View By its Name

5 posts, 0 answered
  1. CafeDelMar
    CafeDelMar avatar
    28 posts
    Registered:
    06 May 2007
    22 Jun 2010
    Link to this post
    Dear Telerik Team

    Is it possible to get Object View by its name?
    My goal is to use single createhostviewcommand for all views (Custom Control)
    ex : createhostviewcommand<someclass.getObjectReference(string viewName)>();

    Thanks
    Febry Nastrioman
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    22 Jun 2010
    Link to this post
    Hi CafeDelMar,


    CreateHostViewCommand and its overloads can be used only for generating commands to the views in the current hierarcy or route, as we will call it.

    Below is a sample that shows creating a command for ViewModeUserControl based View

    link1.NavigateUrl = CreateHostViewCommand("ModuleView", null, null);

    You might find this post How to navigate among Views? useful.


    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. CafeDelMar
    CafeDelMar avatar
    28 posts
    Registered:
    06 May 2007
    22 Jun 2010
    Link to this post
    Hi Ivan

    Thanks for your response

    Sorry if i didn't explain my goal clearly

    I have three views which are inherited from ViewModeControl,
    I want to generate command (using createhostviewcommand<View>())

    This is my code and it works

    foreach (IFunction iFunction in readAllFunction)
    {
       switch (iFunction.ViewName)
       {
          case "ConfigurationView":
             iFunction.Url = CreateHostViewCommand<ConfigurationView>();
             break;
          case "UsersView":
             iFunction.Url = CreateHostViewCommand<UsersView>();
             break;
          case "UserGroupsView":
             iFunction.Url = CreateHostViewCommand<UserGroupsView>();
             break;
       }
       functionData.Add(new Function(iFunction.ViewName,iFunction.Url));
    }

    but use "switch case" makes my code looks not good, i just want to make it simple
    by change the code above using single CreateHostViewCommand as like as

    foreach (IFunction iFunction in readAllFunction)
    {
       iFunction.Url = CreateHostViewCommand<SomeClass.GetObjectReference(iFunction.ViewName)>();  
       functionData.Add(new Function(iFunction.ViewName,iFunction.Url));
    }

    Is it possible?

    Thanks
    Febry Nastrioman
  4. CafeDelMar
    CafeDelMar avatar
    28 posts
    Registered:
    06 May 2007
    27 Jun 2010
    Link to this post
    Dear Telerik Team

    Please advice

    Thanks
  5. CafeDelMar
    CafeDelMar avatar
    28 posts
    Registered:
    06 May 2007
    13 Jul 2010
    Link to this post
    Hi Ivan

    I got the answer for my case and its really works

    foreach (IFunction iFunction in readAllFunction)
    {
     
       Type subViewType = Type.GetType(iFunction.ViewNamespace);
     
       Type viewType = Type.GetType(iFunction.ParentViewNamespace);  
       
       iFunction.Url = CreateRootViewCommand(typeof(ShoppingCartControlPanel), viewType, subViewType);
       functionData.Add(new Function(iFunction.ViewName,iFunction.Url));
    }

    Thanks
    Febry Nastrioman
Register for webinar
5 posts, 0 answered