views:

170

answers:

2

Hi all,

I am using T4MVC in our ASP.NET MVC Project.

I have a statement like this in my view

<% Html.RenderPartial(MVC.SomeController.Views.PartialViewName); %>

Which was previously like this

<% Html.RenderPartial("../SomeController/PartialViewName"); %>

Previously it was working fine, but after I specified the partial view using T4MVC, its not able to locate that partial view.

Its Just trying to find it in the below paths, which is the default behaviour.

~/Views/SomeController
~/Views/Shared

Is there a way to specify a partial view which is in some other controller's views folder through T4MVC? or Whatever I am doing, is it correct ? What am I missing ?

Thanks

+2  A: 

One approach - you can extend your viewengine and make it aware about specific partial view locations. I myself put all partial views in Views/Home/Partial (where Home=>controller name) folder.

 public class ViewEngine : WebFormViewEngine
    {
        public ViewEngine()
        {
            PartialViewLocationFormats = PartialViewLocationFormats
                .Union(new[]
                       {
                           "~/Views/{1}/Partial/{0}.ascx",
                           "~/Views/Shared/Partial/{0}.ascx",
                       }).ToArray();
        }
    }

But it sounds more that you are structuring your app wrong. Controller specific partial views should not render partial views that are tied with another controller. Put those partial views in shared folder.

Arnis L.
+1 for pointing out about the structuring of the app.. Thanks!
Mahesh Velaga
+1  A: 

As you may already know, I have changed T4MVC to generate the full path to the view instead of the short name. So the original code you have above should just work. Let me know if you run into issues.

This is in build 2.6.03. Download Page.

David Ebbo