views:

172

answers:

2

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

A: 

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.

Check out this link.

Also this one gives more info.

griegs
This is not necessarily using the MVC Framework, but sort of an MVC Pattern like approach to web projects. Like I said, the page files live in one project while the codebehind and class files live in another project, which itself is in another directory. That is why I sort of tagged it MVC, but not necessarily using the MVC Framework here. Essentially, I need to be able to reference the VirtualPath of the Usercontrol somehow, so I can load it onto my page dynamically. Any idea how I can do this?
Kobojunkie
A: 

Hi

Did anyone find the solution to this issue? I am using virtual path providers, and would like to have Page.LoadControl(relativePath) go though the provider so that the relative path gets correctly mapped to the virtual path.

~Shuchi

Shuchi