开发者

T4MVC not picking up the Views in Areas (ASP.NET MVC 3 RTM)

T4MVC is working fine everywhere except in Areas.

In Areas, it picks up the Controllers and the Actions, but not the Views.

So, I cannot write, in my controller:

return View(MVC.MyArea.MyController.Views.MyView);

Outside of the Areas, I CAN write:

return View(Views.MyOtherView);

I c开发者_运维技巧an also refer to actions in my area controllers:

MVC.MyArea.MyController.MyAction()

In other words:

a. I can get anything I want, if it is not in an Area.

b. I can get at the Actions in my Area controllers.

c. But I CANNOT get my Views in my Area.

What could the problem be?

TIA

EDIT:

The issue is getting T4MVC to rerun (see David Ebbo's answer and my "answer").


What you have should work, and I verified it by:

  • Creating a new MVC3 app and adding the latest T4MVC 2.6.40 (via nuget)
  • Adding an Area named MyArea
  • Adding a controller named MyController
  • Adding a view named MyView
  • Make sure you rerun the T4MVC.tt custom tool

After that, I'm able to write:

namespace Mvc3Application.Areas.MyArea.Controllers {
    public partial class MyController : Controller {
        public virtual ActionResult Index() {
            return View(Views.MyView);
        }
    }
}

or

namespace Mvc3Application.Areas.MyArea.Controllers {
    public partial class MyController : Controller {
        public virtual ActionResult Index() {
            return View(MVC.MyArea.My.Views.MyView);
        }
    }
}

Note that in the second case, the token in 'My' instead of 'MyController', which is the way it always works.

Please try following those steps in a clean app to see if it works.


I believe my issue is being caused by T4MVC not rerunning. As a result (I speculate) the T4MVC does not update to reflect changes in your project. For example, changing the parameters of an Action in a Controller. Or (specific to this question) adding a new View.

The T4MVC documentation on getting itself to rerun is vague, but points you at a VS add in called Chirpy.

Chirpy installs, and then you have to go in an configure it. You do this by opening Visual Studio, then going to Tools >> Options and choosing the Chirpy option.

See the image:

T4MVC not picking up the Views in Areas (ASP.NET MVC 3 RTM)

I had to add the template name T4MVC.tt bit to get it to work. Not sure if this is necessary or why. But it all now works fine.

If there is a better way of doing this, please let me know.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜