开发者

T4MVC MVC2 Views in Areas not generated

I just create an empty MVC2 project. Add an Area and a controller and a view to it. Include T4MVC files into the project and run the custom tool.

Everything is generated except the ViewNames for the views in the Area.

My tree structu开发者_如何学编程re:

Areas

  • MyArea
    • Controllers

      • MyTestController.cs
    • Views

      • MyTest

        • MyTestView.aspx
      • MySecondTestView.aspx

As you can I have views directly in Views folder and also in folders named by the controller..

Did anyone experienced something like this?


T4MVC definitely supports accessing the views in an Area. I just tried the following on a new project:

  • Create an Area named 'Stuff'
  • Create a Foo controller in there
  • In that controller, right click on Index() and ask it to generate a view
  • Rerun the T4MVC custom tool

After that, I'm able to write either:

    public virtual ActionResult Index()
    {
        return View(Views.Index);
    }

or

    public virtual ActionResult Index()
    {
        return View(MVC.Stuff.Foo.Views.Index);
    }


ASP.NET MVC 2 works, out of the box, using naming conventions to link views to controller actions. These conventions allow it find default views for actions in a controller.

For example, MyTestController.cs will have actions. Lets say it only has one, Test.

By default, MVC framework will look for a view called Test.aspx in a folder MyArea/Views/MyTest

If it doesn't find it there, it will look for the view Test.aspx under /MyArea/Views/Shared

Then it will look in /Views/Shared.

[I might be missing one location, am sure there are 4, but can't remember the other one... Anyway, the principle stands]

If it can't find Test.aspx in any of those locations, it will complain.

You seem to be fighting these conventions. And that will lead you into all kinds of complications. So it is best to read a good book on MVC and really learn the basics of how MVC is designed to work.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜