Updated Web.UI project to support MVC and VS MVC dialogs.
Updated RenderViewPage to include UmbracoContext and DocumentRequest.
This commit is contained in:
@@ -45,3 +45,4 @@ src/Umbraco.Tests/config/applications.config
|
||||
src/Umbraco.Tests/config/trees.config
|
||||
src/Umbraco.Web.UI/web.config
|
||||
src/Umbraco.Tests/config/404handlers.config
|
||||
src/Umbraco.Web.UI/Views/*
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{4C4C194C-B5E4-4991-8F87-4373E24CC19F}</ProjectGuid>
|
||||
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
|
||||
<ProjectTypeGuids>{E53F8FEA-EAE0-44A6-8774-FFD645390401};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ApplicationIcon>
|
||||
@@ -1306,6 +1306,7 @@
|
||||
<DependentUpon>applications.config</DependentUpon>
|
||||
<SubType>Designer</SubType>
|
||||
</None>
|
||||
<Content Include="Views\Home.cshtml" />
|
||||
<None Include="web.Template.Debug.config">
|
||||
<DependentUpon>Web.Template.config</DependentUpon>
|
||||
<SubType>Designer</SubType>
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace Umbraco.Web.Mvc
|
||||
Path.Combine(Server.MapPath(Constants.ViewLocation), template + ".cshtml")))
|
||||
{
|
||||
LogHelper.Warn<RenderMvcController>("No physical template file was found for template " + template);
|
||||
return Content("No template");
|
||||
return Content("");
|
||||
}
|
||||
|
||||
return View(template, model);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
@@ -30,11 +31,14 @@ namespace Umbraco.Web.Mvc
|
||||
{
|
||||
if (UmbracoContext.Current == null)
|
||||
{
|
||||
return new MvcHandler(requestContext);
|
||||
throw new NullReferenceException("There is not current UmbracoContext, it must be initialized before the RenderRouteHandler executes");
|
||||
}
|
||||
var docRequest = UmbracoContext.Current.DocumentRequest;
|
||||
if (docRequest == null)
|
||||
{
|
||||
throw new NullReferenceException("There is not current DocumentRequest, it must be initialized before the RenderRouteHandler executes");
|
||||
}
|
||||
|
||||
var docRequest = UmbracoContext.Current.DocumentRequest;
|
||||
|
||||
var renderModel = new RenderModel()
|
||||
{
|
||||
CurrentNode = docRequest.Node
|
||||
@@ -43,6 +47,7 @@ namespace Umbraco.Web.Mvc
|
||||
//put essential data into the data tokens, the 'umbraco' key is required to be there for the view engine
|
||||
requestContext.RouteData.DataTokens.Add("umbraco", renderModel); //required for the RenderModelBinder
|
||||
requestContext.RouteData.DataTokens.Add("umbraco-doc-request", docRequest); //required for RenderMvcController
|
||||
requestContext.RouteData.DataTokens.Add("umbraco-context", UmbracoContext.Current); //required for RenderViewPage
|
||||
|
||||
return GetHandlerForRoute(requestContext, docRequest);
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Web.Mvc;
|
||||
using Umbraco.Web.Routing;
|
||||
|
||||
namespace Umbraco.Web.Mvc
|
||||
{
|
||||
@@ -7,25 +8,30 @@ namespace Umbraco.Web.Mvc
|
||||
/// </summary>
|
||||
public abstract class RenderViewPage : WebViewPage<RenderModel>
|
||||
{
|
||||
//protected RenderViewPage()
|
||||
//{
|
||||
protected RenderViewPage()
|
||||
{
|
||||
|
||||
//}
|
||||
}
|
||||
|
||||
//protected override void InitializePage()
|
||||
//{
|
||||
// //set the model to the current node if it is not set, this is generally not the case
|
||||
// if (Model != null)
|
||||
// {
|
||||
// //this.ViewData.Model = Model;
|
||||
// var backingItem = new DynamicBackingItem(Model.CurrentNode);
|
||||
// var dynamicNode = new DynamicNode(backingItem);
|
||||
// CurrentPage = dynamicNode;
|
||||
// }
|
||||
//}
|
||||
protected override void InitializePage()
|
||||
{
|
||||
//set the model to the current node if it is not set, this is generally not the case
|
||||
if (Model != null)
|
||||
{
|
||||
////this.ViewData.Model = Model;
|
||||
//var backingItem = new DynamicBackingItem(Model.CurrentNode);
|
||||
//var dynamicNode = new DynamicNode(backingItem);
|
||||
//CurrentPage = dynamicNode;
|
||||
}
|
||||
DocumentRequest = (DocumentRequest)ViewContext.RouteData.DataTokens.GetRequiredObject("umbraco-doc-request");
|
||||
UmbracoContext = (UmbracoContext)ViewContext.RouteData.DataTokens.GetRequiredObject("umbraco-context");
|
||||
}
|
||||
|
||||
public UmbracoContext UmbracoContext { get; private set; }
|
||||
|
||||
//public dynamic CurrentPage { get; private set; }
|
||||
internal DocumentRequest DocumentRequest { get; private set; }
|
||||
|
||||
public dynamic CurrentPage { get; private set; }
|
||||
|
||||
//private ICultureDictionary _cultureDictionary;
|
||||
//public string GetDictionary(string key)
|
||||
|
||||
41
src/Umbraco.Web/RouteValueDictionaryExtensions.cs
Normal file
41
src/Umbraco.Web/RouteValueDictionaryExtensions.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
|
||||
namespace Umbraco.Web
|
||||
{
|
||||
internal static class RouteValueDictionaryExtensions
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Converts a route value dictionary to a form collection
|
||||
/// </summary>
|
||||
/// <param name="items"></param>
|
||||
/// <returns></returns>
|
||||
public static FormCollection ToFormCollection(this RouteValueDictionary items)
|
||||
{
|
||||
var formCollection = new FormCollection();
|
||||
foreach (var i in items)
|
||||
{
|
||||
formCollection.Add(i.Key, i.Value != null ? i.Value.ToString() : null);
|
||||
}
|
||||
return formCollection;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the value of a mandatory item in the route items
|
||||
/// </summary>
|
||||
/// <param name="items"></param>
|
||||
/// <param name="key"> </param>
|
||||
/// <returns></returns>
|
||||
public static object GetRequiredObject(this RouteValueDictionary items, string key)
|
||||
{
|
||||
if (key == null) throw new ArgumentNullException("key");
|
||||
if (!items.Keys.Contains(key))
|
||||
throw new ArgumentNullException("The " + key + " parameter was not found but is required");
|
||||
return items[key];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@ namespace Umbraco.Web.Routing
|
||||
//TODO: When this is not IIS 7, this does not work for the root '/' request since it comes through as default.aspx!!
|
||||
// this needs fixing.
|
||||
|
||||
//format the path
|
||||
//format the path, thsi needs fixing when pre-IIS7
|
||||
route = route.Replace(".aspx", "");
|
||||
|
||||
var node = LookupDocumentNode(docreq, route);
|
||||
|
||||
@@ -253,6 +253,7 @@
|
||||
<Compile Include="Mvc\RenderViewEngine.cs" />
|
||||
<Compile Include="Mvc\RenderViewPage.cs" />
|
||||
<Compile Include="Mvc\RouteDefinition.cs" />
|
||||
<Compile Include="RouteValueDictionaryExtensions.cs" />
|
||||
<Compile Include="WebBootManager.cs" />
|
||||
<Compile Include="LegacyRequestInitializer.cs" />
|
||||
<Compile Include="Mvc\ControllerExtensions.cs" />
|
||||
|
||||
@@ -62,10 +62,19 @@ namespace Umbraco.Web
|
||||
return uri.Rewrite(path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Uri to a path based URI that is lower cased
|
||||
/// </summary>
|
||||
/// <param name="uri"></param>
|
||||
/// <returns></returns>
|
||||
public static Uri UriToUmbraco(Uri uri)
|
||||
{
|
||||
var path = uri.GetSafeAbsolutePath();
|
||||
|
||||
//we need to check if the path is /default.aspx because this will occur when using a
|
||||
//web server pre IIS 7 when requesting the root document
|
||||
//if this is the case we need to change it to '/'
|
||||
|
||||
path = path.ToLower();
|
||||
if (path != "/")
|
||||
path = path.TrimEnd('/');
|
||||
|
||||
@@ -10,7 +10,6 @@ using umbraco.businesslogic;
|
||||
|
||||
namespace Umbraco.Web
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// A bootstrapper for the Umbraco application which initializes all objects including the Web portion of the application
|
||||
/// </summary>
|
||||
|
||||
@@ -212,7 +212,8 @@ namespace umbraco
|
||||
}
|
||||
|
||||
//TODO: This should be removed, we should be handling all 404 stuff in the module and executing the
|
||||
// DocumentNotFoundHttpHandler instead.
|
||||
// DocumentNotFoundHttpHandler instead but we need to fix the above routing concerns so that this all
|
||||
// takes place in the Module.
|
||||
void RenderNotFound()
|
||||
{
|
||||
Context.Response.StatusCode = 404;
|
||||
|
||||
Reference in New Issue
Block a user