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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:41:20+00:00 2026-06-18T23:41:20+00:00

Been picking up MVC4 and Razor and having a ball, but I’ve got a

  • 0

Been picking up MVC4 and Razor and having a ball, but I’ve got a question on the approach for what I want to acheive:

I have a page with some panels on (Like a dashboard), and a set of icons you can drag and drop to these panels to ‘install’ a module into that panel, and display it’s content. This is great from a UI point of view, now I’m looking at hooking this up to something a bit meatier:

What I have:

  • IContentModule
  • Set of concrete classes for each module with a Render() method
  • Controller that handles module drop event and an Activator to get an instance of the class for that module drop

Simple stuff really, ideally, I want it so that each module is responsible for it’s own content, but aside from having a string return from Render, is there a better way, like, assigning a specific view markup to that particular concrete class, so that I can have control over what is being rendered, but in a much more structured way, wondering what the best approach is here?

Thanks for your time!

Danny

Edit: Sorta thinking if there was a way to couple a view to my concrete classes? e.g. ViewForum.cshtml binding to ForumModule.cs, somehow instantiating the view and getting a string from it’s render of the object, then passing that back via a string to insert into my panel?

An example of a panel:

<section class="main box droppable" id="MainPanel">
<div class="padding">
Panel 1
</div>
</section>

The jQuery event

 $(".droppable").droppable({
        hoverClass: 'boxhover',
        drop: function (event, ui) {
            $.ajax({
                type: "POST",
                url: '/Home/AddModule/' + $(ui.draggable).attr("id") + "?returnTo=" + this.id,
                success: function(data) {
                $("#" + data.Target).html(data.Content);
                }
            });
        }
    });

The controller method

        [AcceptVerbs(HttpVerbs.Post)]
    public JsonResult AddModule(string id, string returnTo)
    {

        string content = DemoResolve(id);
        try
        {
            IContentModule module  =  (IContentModule)  Activator.CreateInstance(Type.GetType("Foo.Bar.BLLForumModule,Foo.Bar"));
            content  = module.Render();
        }catch(Exception exp)
        {
            throw;
        }
        return Json(new { Target = returnTo, Content = content });
    }

So where i have that module.Render(), i’m thinking I’d want to get a partial view or something and render that based on the object I have in hand

  • 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-18T23:41:21+00:00Added an answer on June 18, 2026 at 11:41 pm

    Worked with a colleague of mine and came up with a solution of binding the views and the modules together in a sort of dynamic way, for example, if the jQuery post comes back with the string of the module ‘BLLForumModule’ we have the following:

        [AcceptVerbs(HttpVerbs.Post)]
        public JsonResult AddModule(string id, string returnTo)
        {
    
            string content = DemoResolve(id);
            try
            {
                content = RenderView("BLLForumModule");
            }catch(Exception exp)
            {
                throw;
            }
            return Json(new { Target = returnTo, Content = content });
        }
    
    private string RenderView(string moduleName)
        {
            string result = "";
    
            IContentModule module = (IContentModule)Activator.CreateInstance(Type.GetType("Foo.Bar." + moduleName  +",Foo.Bar"));
    
            this.ViewData.Model = module;
    
            using (var sw = new System.IO.StringWriter())
            {
    
                ViewEngineResult viewResult = ViewEngines.Engines
    
                .FindPartialView(this.ControllerContext, moduleName);
    
                var viewContext = new ViewContext(this.ControllerContext,
    
                viewResult.View, this.ViewData, this.TempData, sw);
    
                viewResult.View.Render(viewContext, sw);
    
                result = sw.GetStringBuilder().ToString();
    
            }
            return result;
        }
    

    This assumes there is a class in the Foo.Bar assembly with the same name as the view we are trying to load (BLLForumModule.cshtml and Foo.Bar.BLLForumModule.cs)

    I then take the rendered content from the view and spit it back as a JsonResult as the Content part and the Target part of the JsonResult as the ID of the panel it needs to be dropped into.

    This feels pretty good I think, any suggestions or improvements welcome!

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

Sidebar

Related Questions

Been slowly picking up the basics in IOS Programming, but seemed to have hit
I know similar questions (regarding cherry-picking) have been asked before, but I haven't really
I've been picking my way though django-paypal documentation and have got a signal connecting
So I have been trying to understand the concept of 3D picking but as
I haven't been programming on the iPhone for very long, but I'm picking it
Been hustling with this for a while but cant still get the page to
I am new to Android development so have been picking things up over the
This may be a basic question... However I've just been picking a solution without
I have only recently started picking up VBA in excel and I have been
I have been picking my brain lately and can't seem to figure out how

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.