More in this section
Forums / Developing with Sitefinity / Using Custom module API in MVC Widgets

Using Custom module API in MVC Widgets

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
3 posts, 1 answered
  1. Gary
    Gary avatar
    28 posts
    Registered:
    16 May 2012
    16 Sep 2013
    Link to this post
    Hi,

    I'm struggling trying to create an MVC widget based on a custom module built using the module builder.

    private Type myType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.SomeModel.ModuleName.Type");
     
           public ActionResult Index()
           {
               try
               {
                   DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
                   IQueryable blah = dynamicModuleManager.GetDataItems(this.myType );
                    
                   return View("Default", blah);
               }
               catch
               {
                   return View("Error");
               }
    }

    On the View, I set:

    @model IQueryable<SitefinityWebApp.Mvc.Models.MyModel>

    It then displays the error:
    Unable to cast object of type 'Telerik.Sitefinity.DynamicTypes.SomeModel.ModuleName.Type' to type 'SitefinityWebApp.Mvc.Models.MyModel'.

    So I then changed it to :
    @model IQueryable<Telerik.Sitefinity.DynamicTypes.SomeModel.ModuleName.Type>

    And now I get the error:
    CS0234: The type or namespace name 'SomeModel' does not exist in the namespace 'Telerik.Sitefinity.DynamicTypes.Model' (are you missing an assembly reference?)

    Any ideas how I can get this module to work with an MVC widget? 

    Thanks

    Gary
  2. Gary
    Gary avatar
    28 posts
    Registered:
    16 May 2012
    16 Sep 2013
    Link to this post
    Solved it!

    In my controller:
    private Type flightType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.LiveTest.Flight");
     
        public ActionResult Index()
        {
            try
            {
                DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
                var Test = GetDataItems();
                return View("Default", Test);
            }
            catch
            {
                return View("Error");
            }
        }
     
        public List<DynamicContent> GetDataItems()
        {
            DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
     
            var Test = dynamicModuleManager.GetDataItems(this.flightType)
                .Where(i => i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live && i.Visible == true).ToList();
     
            return Test;
        }


    And in my view:
    @using Telerik.Sitefinity.Model
    @model List<Telerik.Sitefinity.DynamicModules.Model.DynamicContent>
     
     
    <table>
     @foreach (var test in Model) {
         <tr><td>@Html.Raw(test.GetValue("testNo").ToString())</td></tr>
        }
    </table>

    Answered
  3. Bill
    Bill avatar
    5 posts
    Registered:
    13 Dec 2010
    05 Oct 2015 in reply to Gary
    Link to this post
    thanks for posting your solution. Helped me too!
3 posts, 1 answered