asp.net mvc 2 preview 2 and Spark

独自空忆成欢 提交于 2019-12-12 13:29:13

问题


Some body tried Spark View Engine with asp.net mvc 2 preview 2?

I have a problem with AREAS.

It looks likes spark engine looks **.spark* files inside of Views folders only instead of Areas folder in additionally.

My question is:

Somebody has information how to add it?


回答1:


Spark will not automatically check the area views location in the current version. If you're willing to change the source (which i assume you are if you're doing mvc 2 stuff), here's the fix:

You have to modify the file src\Spark.Web.Mvc2\Descriptors\AreaDescriptorFilter.cs so that it reads as below (changes highlighted by **):

Note: I don't have the machine i did this on with me, so the slashes in the format string MIGHT need to be forward slashes.

Also, it is possible to create this class in your own code and pass it in when you register the view engine, but I don't remember the configuraiton code off the top of my head.

That's the approach I did since I wanted to modify the spark source as little as possible.

  public class AreaDescriptorFilter : DescriptorFilterBase
{
    **private const string areaPathFormatString = "~\\Areas\\{0}\\Views";**
    public override void ExtraParameters(ControllerContext context, IDictionary<string, object> extra)
    {
        object value;
        if (context.RouteData.Values.TryGetValue("area", out value))
            extra["area"] = value;
    }

    public override IEnumerable<string> PotentialLocations(IEnumerable<string> locations, IDictionary<string, object> extra)
    {
        string areaName;

        return TryGetString(extra, "area", out areaName)
                   **? locations.Select(x => Path.Combine(string.Format(areaPathFormatString,areaName), x)).Concat(locations)**
                   : locations;
    }
}



回答2:


Spark looks for a constraint or default value key "area" in a route to determine the view location. MVC 2 area support does not add this by default, you have to do it when declaring your area:

public class AdminRoutes : AreaRegistration
{
    public override string AreaName
    {
        get { return "admin"; }
    }

    public override void RegisterArea(AreaRegistrationContext context)
    {
        context.MapRoute(
            "admin_default",
            "Admin/{controller}/{action}/{id}",
            new { controller = "Dashboard", action = "Index", id = "", area = "admin" },
            new [] { "MyProject.Areas.Admin.Controllers" });
    }
}

Note the area = "admin" inside the defaults object.



来源:https://stackoverflow.com/questions/1589763/asp-net-mvc-2-preview-2-and-spark

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!