You can simply wrap the contents of the plugin in a DIV or FORM element and specify a unique identifier on the page. Then just use jQuery only to select the elements that are inside this "parent" DIV or FORM element.
You may have generated a GUID to use as a unique identifier at runtime, but it will take some work by the person who wrote the plugin. Although perhaps you could create one to automatically generate the “parent” DIV and ID, then you could just access the ID in the view as a plugin property.
Just some thoughts, I haven't built an ASP.NET MVC system with plugins yet, but that doesn't seem too complicated.
Here is an example of a PartialView that uses its own ViewUserControl class:
ViewUserControl1.ascx:
<%@ Control Language="C#" Inherits="MvcPluginPartialView.PluginViewUserControl" %> <input class="txtText" type="text" value="<%=this.ID %>" /> <input class="txtButton" type="button" value="Show Alert" /> <script type="text/javascript"> jQuery(function() { </script>
MvcPluginPartialView.PluginViewUserControl:
namespace MvcPluginPartialView { public class PluginViewUserControl : ViewUserControl { public PluginViewUserControl() { this.ID = "p" + Guid.NewGuid().ToString().Replace("-", ""); } public override void RenderView(ViewContext viewContext) { viewContext.HttpContext.Response.Cache.SetExpires(DateTime.Now); ViewUserControlContainerPage containerPage = new ViewUserControlContainerPage(this);
Then, to place the view on the page, you can use the "Html.RenderPartial" method, as usual, plus you can place as many on them as you want, and they will all work as expected.
<%Html.RenderPartial("ViewUserControl1"); %> <%Html.RenderPartial("ViewUserControl1"); %> <%Html.RenderPartial("ViewUserControl1"); %>
source share