I'm trying to create reusable "zones" but am having trouble figuring out how to give them all unique ids.
What I'd like is to be able to create a component which can be put on an mvc page using the usercontrol syntax or using RenderAction or RenderPartial. I want to be able to update these components' content using ajax, so I need someway to reference them by id. However, there is no mechanism in MVC that wraps anything in a div or something like that.
I've learned that if I extend ViewUserControl and put the controls on the page like so:
<Zones:TestControl runat="server" ID="TestControl1" />
Then I can use the 'ClientID' property to get the unique ID generated. However, if I use RenderAction or RenderPartial in another request, obviously the control hierarchy is missing, so the ID is just 1. So to get around this I made a simple base class like so:
public class BaseZone<TModel> : System.Web.Mvc.ViewUserControl<TModel>
protected string zoneId;
public string ZoneId
string zoneId = ViewData["ZoneId"] as string;
View Complete Post