1

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?

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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" />
        ...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.