Is it possible to create a partial view as independent "widget"?

asp.net-mvc, partial-views

Solution

You can use the RenderAction method to render a Partial view. The partial view can be associated with a Model that is different from the calling page's Model

Calling the action method from the View

@{Html.RenderAction("SomeAction", "SomeController");} 

Action method returns the partial view

public ActionResult SomeAction()
        {
            //Construct SomeModel here..  
            return PartialView("SomeView", SomeModel);
        }

Problem

With old ASP.NET we could create User controls(.ascx) easily, in fact many controls were/are fully independent from the current View. I wonder if the same is possible with MVC? I need to display simple list with users, problem is - this list should be displayed in more then one places on my site. While I can simply modify my views models, and add model of the "widget" to them, I would like to avoid this. Preferably I would like my users list to require only the following: ``` @Html.Partial("Link/To/My/List") ``` to be included in other View - list's model would have to be populated some other way. I thought to use AJAX inside my partial but this seems like a bad idea. Is there any other way around it or is it simply a bad idea that breaks MVC assumptions?

Original source

Related problems