tags:

views:

34

answers:

2

I am working in an environment with many teams who are responsible for specific content on pages. Each team is sharing specific information (common class libraries, and master pages) that each are going deliver different types of content.

Is it possible for an MVC application to do something similar to RenderPartial and pass a model to another MVC application Controller/Action to return content?

So the code for this might look like: (http://www.mydomain.com/Home/Index)

<% Html.RenderAction("ads.mydomain.com", "Home", "Index", AdModel) %>

Maybe this is not a good idea as another thread has to spin up to server a partial view?

A: 

In principal yes, though your question is a little vague.

Have a look at "portable areas" within MvcContrib on codeplex. This technique allows separate teams to develop separate MVC apps that would then be orchestrated by a central application.

Clicktricity
One of the goals is not to have one giant monolithic application running. I'll look into portalable areas, that might be what I'm looking for.
Erik Philips
A: 

No, RenderPartial/RenerAction can only load views that it can access via reflection, not via HTTP requests to external resources.

If the MVC app for 'ads.mydomain.com' is available to you at compile them then you can utilise its resources via Areas, however it won't pickup the changes if they release a new version to the 'ads.mydomain.com' website without you getting their latest assembly and re-compiling and deploying your app as well.

You can do similar stuff with AJAX where you can load a fragment from another site, however it wouldn't be done server side, and would require the client to have javascript enabled. Also the model would need to be converted to JSON and posted to the request, so its a bit of a hacky solution.

You could write an extension method (lets call it Html.RenderRemote) which does all the work for you of creating an http connection to the target and requests the URL. You'd have to serialize the model and send it as part of the request.

public static string RenderRemote(this HtmlHelper, string url, object model)
{
    // send request to 'url' with serialized model as data
    // get response stream and convert to string
    // return it
}

You could use it as :

<%= Html.RenderRemote('http://ads.mydomain.com', Model');

You wouldn't be able to take advantage of the routes on the remote domain, so you'd have to construct the literal URL yourself, which means if they change your routing rules your URL won't work anymore.

Michael Shimmins