tags:

views:

106

answers:

2

I have an MVC view which is using a model, and I am after injecting some HTML for additional content which is not part of the model.

I don't know the content of the injected HTML or text fields as they will be plugins.

How can I pick up the changes to both the existing model and capture the plug-in HTML fields?

+1  A: 

you can use an HtmlHelper extension to do this if you want:

namespace MyExtensions
{
    public static class HtmlHelperExtensions
    {
        pubilc static string EmitPluginData(this HtmlHelper htmlHelper)
        {
            var pluginData = GetPluginDataFromSomeWhere();
            return pluginData;
        }
    }
}

Then you can use this in your views:

<html>
<body>
    <%= ViewData["SomeData"] %>
    <%= Html.EmitPluginData() %>
</body>
</html>

Just don't forget to add the namespace to your web.config:

<pages>
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="MyExtensions" />
        ...
free-dom
+3  A: 

RenderAction from the MvcFutures is really handy for this and feels a bit cleaner than having HtmlHelpers with intimate knowledge of your plugin architecture IMHO.

Wyatt Barnett