Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8143377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:06:30+00:00 2026-06-06T13:06:30+00:00

We have a ViewModel with a collection of Widget<dynamic> : public class Widget<T> {

  • 0

We have a ViewModel with a collection of Widget<dynamic>:

public class Widget<T>
{
    public string ViewName { get; set; }
    public T Data { get; set; }
}

In our View we loop through the collection of widgets and call Html.Partial.

@foreach (var widget in Model) {
    @Html.Partial(widget.ViewName, widget)
}

This works providing the partial has a dynamic model or a model of Widget<dynamic>.

However, I would like intellisense within the partial view so I give my view a model of the appropriate widget data type e.g:

@model Widget<string>

Unfortunately this throws an exception as @Html.Partial is casting the dynamic model as System.Object.

Aside from manually casting the widget again within the partial, is there a way to call Html.Partial without having the dynamic model cast as an object?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T13:06:32+00:00Added an answer on June 6, 2026 at 1:06 pm

    Create a interface and all dynamic object type widgets must implements the interface, I did the same a time ago and worked smooth

    Simple example with render: (it’s just a quick example you must complete)

        public interface IWidget{
    
         public System.Web.Mvc.MvcHtmlString RenderMyWidget(HtmlHelper helper);
    
    }
    
    
    
    
    public class ContenidoWidgets : IWidget{
    
        private String Controller { get; set; }
    
        private String Action { get; set; }
    
        private Object Parms {get; set; }
    
        public ContenidoWidgets(String controller, String action, Object parms)
        {
    
            this.Controller = controller;
            this.Action = action;
            this.Parms = parms;
    
        }
    
        public System.Web.Mvc.MvcHtmlString RenderMyWidget(HtmlHelper helper){
    
            return System.Web.Mvc.Html.ChildActionExtensions.Action(helper, this.Action, this.Controller, this.Parms);
    
        }
    

    the view….

    @model IWidget
    
    @model.RenderMyWidget(this.html);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a viewmodel. public class RegistrationViewModel { public RegisterModel Register { get; set;
I have a ViewModel that looks like this: public class CreateReviewViewModel { public string
I have a viewmodel that contains a product and SelectList of categories. public class
I have a ViewModel in WPF that looks something like this: public class SwatchViewModel
My situation is this: I have this ViewModel: public class RealtyViewModel { public RealtyViewModel()
I have in ViewModel a collection, with ICollectionView view; Well, in XAML I have
I have ViewModel class as follows: public class ListViewModel { public ObservableCollection<InfoItem> List {
If i have a ViewModel like this: public class MyViewModel { [UIHint(SomeTemplate)] public ICollection<SomeViewModel>
Given that I have the following widget (and a view attached to it): public
I have a class that inherits the base Collection class (ViewModel for a dataGridRow)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.