Re: MVC 2 Areas could not work

3 views
Skip to first unread message

zhen zhu

unread,
Aug 2, 2010, 10:27:43 AM8/2/10
to Spark View Engine Dev
oh~ I got it.
thanks Adam from http://groups.google.com/group/spark-dev/browse_thread/thread/1553c0e4364d4509

btw:
I forget to add the reference of assembly for Web.Areas.Samples.Controllers. :((
maybe the solution from http://www.silverxu.com/making-spark-view-engine-to-work-with-asp-net-mvc-2-areas/ is also useful.


2010/8/2 workingbird <zh....@gmail.com>
===
I've tried use Areas future of MVC 2 in my web.But when I changed the
view engine to Spark, the Areas could not work. It thrown some
problems like 'can not find resources'.

===
My web application with Areas:Samples, Controller: Home, Action:Index.
Here is some codes below.
Code of Controller:
namespace Web.Areas.Samples.Controllers
{
   public class HomeController : Controller
   {
       public ActionResult Index() {return View();}
   }
}

Code of AreaRegistion :
namespace Web.Areas.Samples
{
   public class SamplesAreaRegistration : AreaRegistration
   {
       public override string AreaName {get { return "Samples"; }}
       public override void RegisterArea(AreaRegistrationContext
context)
       {
           context.MapRoute(
               "Samples_default",
               "Samples/{controller}/{action}/{id}",
               new {  Area = "Core",action = "Index", id =
UrlParameter.Optional }
               //new { controller = "Home", action = "Index", id =
"", area = "Core" } //I have tried to add 'area' to route key, but it
seems not take any effect.
           );
       }
   }
}

Code global.asax.cs:
protected void Application_Start()
{
 SparkEngineStarter.RegisterViewEngine(ViewEngines.Engines);
 AreaRegistration.RegisterAllAreas();

 routes.Add(new Route("{controller}/{action}/{id}", new
MvcRouteHandler())
           {
               Defaults = new RouteValueDictionary(new { action =
"Index", id = "" }),
           });
}

The location of View file in web :
~/Areas/Samples/Views/Home/Index.spark

===
I did some failure tests:
1. To visite another URL for Controller:Home, Action:Index ,like /Home/
Index, is good. The View is located at "~/Views/Home/Index.spark".
2. I had tried to change the source code
PotentialViewLocations.DefaultDescriptorBuilder flowing this article
and recompiled, but is also can not work.
http://www.silverxu.com/making-spark-view-engine-to-work-with-asp-net-mvc-2-areas/
3. there is an AreaDescriptorFilter in source code. And the instance
is added in SparkEngineStarter.CreateContainer struct. I tried these
code below in Application_Start, and it didn't work either:
var services = SparkEngineStarter.CreateContainer();
services.AddFilter(new AreaDescriptorFilter());  //AddFilter or not ,
both have tried.
SparkEngineStarter.RegisterViewEngine(engines, services);

===
Is there some steps i missed? Or some other method can resolve it?
Thanks for any suggestion.

workingbird

unread,
Aug 2, 2010, 9:55:53 AM8/2/10
to Spark View Engine Dev
Reply all
Reply to author
Forward
0 new messages