Reputation: 6545
I have an application with the FrontEnd separated into one Project file and the Codebehind/classes separated into a completely different class library. What I need is a way to, from the UserControl Type
, obtain it's VirtualPath
.
Typically, we would have this in code
Board uc = (Board)Page.LoadControl(@"~\Board.ascx");
But I want is something like this
Board uc = (Board)Page.LoadControl(Board.VirtualPath);
OR
Board uc = Page.LoadControl(Board);
Anyone have an idea how I can accomplish this?
Thanks in advance :)
Upvotes: 1
Views: 1293
Reputation: 22760
Pretty sure your implementation of controls, within the MVC framework, is incorrect.
I think you are trying to load controls whereas you might be thinking of PartialViews.
Normally, here in mvc land, you do something like <% Html.PartialView("PartialViewName", Model); %>
You can, using WebFormViewEngine amd PartialViewLocationFormats specify shared locations of the partial views etc.
You can also, from your view say something like <% Html.PartialView("~/views/myController/PartialViewName", Model); %>
I haven't seen, or heard of, anyone using LoadControl from an MVC application.
You can also create your own HTML Helpers as well as Web Controls but neither of these use LoadControl either.
Sounds like you are trying to re-use your WebForms controls. I'd be possibly converting your web controls to HTML Helpers or WebControls. Research MVC Web Controls.
Also this one gives more info.
Upvotes: 1