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 618719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:34:38+00:00 2026-05-13T18:34:38+00:00

Updated: This is a re-write from my original question (or lack of), the main

  • 0

Updated:

This is a re-write from my original question (or lack of), the main problem I am having at the moment is that when mapping my Widget domain models to the correct ViewModel I am having to do it like this which is definetly not the right solution…

public ProfileWidgetViewModel MapFrom(ProfileWidget input, Account userAccount)
    {
        ProfileWidgetViewModel viewModel = Mapper.Map<ProfileWidget, ProfileWidgetViewModel>(input);

        viewModel.IsLoggedIn = identityTasks.IsSignedIn();

        // we need to use the correct mapper depending on the widget
        switch(input.GetType().Name.ToLower())
        {
            case "htmlwidget":
                viewModel.ProfileWidgetItem = htmlWidgetViewModelMapper.MapFrom((HtmlWidget)input);
                break;

            case "mediawidget":
                viewModel.ProfileWidgetItem = mediaWidgetViewModelMapper.MapFrom((MediaWidget)input, userAccount);
                break;
}

        return viewModel;
    }

Because I am passing in the BaseClass (even though I know I can safely downcast the correct type), I am needing to do a big switch statement to map the Widget viewmodel using the correct class.

I need somehow to make this more dynamic so it can automatically pickup the correct class to use, i’m sure there is a way using generics / reflection to do this, i’m open to suggestions if you think I am going about this the wrong way.

  • 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-05-13T18:34:39+00:00Added an answer on May 13, 2026 at 6:34 pm

    I recommend not to use pop-up windows but to use some modal windows for a page, like jqModal. IMO it’s better for usability than native pop-ups.
    About your widgets, what about to look at the problem from the side of a models? For a widget you’ll have 2 view models – one for displaying and one for editing settings of the widget. It’s better to have 2 different controllers for displaying a widget and for editing settings (I cast SRP principle here). So the first controller will return a widget data model and the second – settings data model. And views, you can use as much as you need, it’s hard to recommend something here using only words and without custom implementation of the project in mind.
    It’s hard to try to answer a vague question. May be you should ask some more specific questions? And check this sample of a portal with widgets, it uses ExtJS library that’s very easy to learn and use and it’s very powerful.

    Edit 02/20/10:
    I prefer to use the following approach (I’ll use a widget with name FooWidget for example). Create 2 controllers with names FooWidgetDataController and FooWidgetSettingsController. Add routes for urls:

    /widgets/FooWidget/data for FooWidgetDataController
    /widgets/FooWidget/settings for FooWidgetSettingsController
    

    Create FooWidgetDataModel:

    public class FooWidgetDataModel {
        public int Column1 {get; set;}
        public int Column2 {get; set;}
        public int Column3 {get; set;}
    }
    

    In the FooWidgetDataController fill the FooWidgetDataModel and return it to some view:

    public class FooWidgetDataController : Controller {
        public ActionResult Index(){
            var model = new FooWidgetDataModel{ Column1=5, Column2=1  }; // loading of data for FooWidgetDataModel
            return View(model); // using a view with name Index.ascx or Index.aspx
        }
    }  
    

    Create FooWidgetSettingsModel:

    public class FooWidgetSettingsModel {
        public bool ShowColumn1 {get; set;}
        public bool ShowColumn2 {get; set;}
        public bool ShowColumn3 {get; set;}
    }
    

    And sample code for FooWidgetSettingsController:

    // add some permission verification attribute here
    public class FooWidgetSettingsController : Controller {
        [AcceptGet]
        public ActionResult Index(){
            var model = new FooWidgetSettingsModel{ ShowColumn1=true, ShowColumn2=false  }; // loading of data for FooWidgetSettingsModel
            return View(model); // using a view with name Index.ascx or Index.aspx
        }
    
        [AcceptPost, ActionName("Index")]
        public ActionResult IndexPost(FooWidgetSettingsModel model){ // model will be automatically binded by built it functionality
            // validate model
            // save settings if valid
            // and return whatever you want here
            return RedirectToAction("Index"); // for example, redirecting to edit page
        }
    }
    

    Using this approach you’ll need to create a controller per widget. Probably you’ll not like it but using some extensions or base classes you will not need to write a lot of code. And code will be easy to read and simple.
    For rendering a widget on a page consider using Html.RenderAction (previously it was in mvc futures assembly, I don’t track changes at the moment).
    Note, keep your controllers as thin as possible and check some best practices for asp.net mvc (link 1 and link 2).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

FINAL UPDATE This question is about how to write a setup.py that will compile
i write a script to list my file from Update directory with this option:
Update: I updated this after doing some digging and realizing that this might be
Updated Question: $(this).attr(EmployeeId, 'A42345'); $.ajax({ type: POST, url: url, data: {EmployeeId: ' + id
This is an updated part 2 of a question I asked earlier. I'm trying
See the next post. This original one question content has been removed, as doesn't
I got this problem from an interview with Microsoft. Given an array of random
somewhat related to: libxml2 from java yes, this question is rather long-winded - sorry.
any better way to write this ? $(this).parent().parent().find( dd ul).toggle(); update.. I am trying
I want add new Feed item on entity persist and update. I write this

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.