Problem with Mobile View Engine

May 15, 2011 at 10:20 PM

I'm combining Scott Hanselman's  MVC Mobile View engine with project awesome's autocomplete.  Each works fine independently, however, if ViewEngine.Engines.Clear() as prescribed in my global.asax.cs, I get the following exception.  If I comment it out, I get the incorrect view to my mobile emulators. Any thoughts?  Thanks in advance.

ModelMetadataProviders.Current = new AwesomeModelMetadataProvider();
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
		
ViewEngines.Engines.Clear();
ViewEngines.Engines.AddIPhone<RazorViewEngine>();      
		ViewEngines.Engines.AddGenericMobile<RazorViewEngine>();
ViewEngines.Engines.Add(new RazorViewEngine());

 

[InvalidOperationException: The partial view '~\Views\Shared\Awesome\Autocomplete.ascx' was not found or no view engine supports the searched locations. The following locations were searched:~\Views\Shared\Awesome\Autocomplete.ascx]   System.Web.Mvc.HtmlHelper.FindPartialView(ViewContext viewContext, String partialViewName, ViewEngineCollection viewEngineCollection) +380334   System.Web.Mvc.HtmlHelper.RenderPartialInternal(String partialViewName, ViewDataDictionary viewData, Object model, TextWriter writer, ViewEngineCollection viewEngineCollection) +266   System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData) +113   System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model) +32   Omu.Awesome.Mvc.Helpers.AutocompleteHelpers.Autocomplete(HtmlHelper html, AutocompleteParams o) +739   Omu.Awesome.Mvc.Helpers.AutocompleteHelpers.Autocomplete(HtmlHelper html, String prop, Object value, String propId, Object propIdValue, String controller, Nullable`1 maxResults, String parentId, Nullable`1 minLength, Nullable`1 delay, Object htmlAttributes, Boolean generatePropId, String prefix, IDictionary`2 data, String area) +303   ASP._Page_Views_Member_FindNames_cshtml.Execute() in c:\Users\rons\Documents\Visual Studio 2010\Projects\MvcApplication_EF_Test\

Coordinator
May 16, 2011 at 6:05 AM

well, it looks like it can't find the awesome views, probably it's looking in some other place,

Or probably it also needs a web-forms viewengine, since the awesome views are ascx not cshtml

May 16, 2011 at 12:17 PM

This piece of code did the trick.

 public static void RegisterViewEngine()
    {
        ViewEngines.Engines.Clear();

        WebFormViewEngine viewEngine = new WebFormViewEngine();

        viewEngine.PartialViewLocationFormats = (new[] {
            "~/Views/Shared/PartialViews/{0}.ascx",
            "~/Views/{1}/PartialViews/{0}.ascx"
          }).Concat(viewEngine.PartialViewLocationFormats).ToArray();

        ViewEngines.Engines.Add(viewEngine);
    }