Skip to content

Commit

Permalink
Add non-matching Razor + DTO Models (e.g. exceptions) to Razor ViewPa…
Browse files Browse the repository at this point in the history
…ge.ModelError and leave Model as null
  • Loading branch information
mythz committed Nov 14, 2012
1 parent 75ef3bf commit b8ed594
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
9 changes: 9 additions & 0 deletions src/ServiceStack.Razor/ViewPageBase.cs
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
using ServiceStack.CacheAccess; using ServiceStack.CacheAccess;
using ServiceStack.Common.Web;
using ServiceStack.Html; using ServiceStack.Html;
using ServiceStack.Messaging; using ServiceStack.Messaging;
using ServiceStack.OrmLite; using ServiceStack.OrmLite;
Expand All @@ -10,6 +11,7 @@
using ServiceStack.ServiceHost; using ServiceStack.ServiceHost;
using ServiceStack.ServiceInterface; using ServiceStack.ServiceInterface;
using ServiceStack.ServiceInterface.Auth; using ServiceStack.ServiceInterface.Auth;
using ServiceStack.ServiceInterface.ServiceModel;
using ServiceStack.WebHost.Endpoints; using ServiceStack.WebHost.Endpoints;


namespace ServiceStack.Razor namespace ServiceStack.Razor
Expand Down Expand Up @@ -42,6 +44,13 @@ public T Get<T>()


public IHttpResponse Response { get; set; } public IHttpResponse Response { get; set; }


public object ModelError { get; set; }

public ResponseStatus ResponseStatus
{
get { return ModelError.ToResponseStatus(); }
}

private ICacheClient cache; private ICacheClient cache;
public ICacheClient Cache public ICacheClient Cache
{ {
Expand Down
21 changes: 12 additions & 9 deletions src/ServiceStack.Razor/ViewPage`1.cs
Expand Up @@ -7,8 +7,8 @@
namespace ServiceStack.Razor namespace ServiceStack.Razor
{ {
public abstract class ViewPage<TModel> : ViewPageBase<TModel> public abstract class ViewPage<TModel> : ViewPageBase<TModel>
{ {
public HtmlHelper<TModel> Html = new HtmlHelper<TModel>(); public HtmlHelper<TModel> Html = new HtmlHelper<TModel>();


private IViewEngine viewEngine; private IViewEngine viewEngine;
public override IViewEngine ViewEngine public override IViewEngine ViewEngine
Expand All @@ -30,18 +30,21 @@ public override Type ModelType
get { return typeof(TModel); } get { return typeof(TModel); }
} }


public override void Init(IRazorViewEngine viewEngine, ViewDataDictionary viewData, IHttpRequest httpReq, IHttpResponse httpRes) public override void Init(IRazorViewEngine viewEngine, ViewDataDictionary viewData, IHttpRequest httpReq, IHttpResponse httpRes)
{ {
this.Request = httpReq; this.Request = httpReq;
this.Response = httpRes; this.Response = httpRes;
Html.Init(httpReq, viewEngine, viewData); Html.Init(httpReq, viewEngine, viewData);
this.Model = (TModel) viewData.Model; if (viewData.Model is TModel)
} this.Model = (TModel)viewData.Model;
else
this.ModelError = viewData.Model;
}


public virtual bool IsSectionDefined(string sectionName) public virtual bool IsSectionDefined(string sectionName)
{ {
//return this.childSections.ContainsKey(sectionName); //return this.childSections.ContainsKey(sectionName);
return false; return false;
} }
} }
} }

0 comments on commit b8ed594

Please sign in to comment.