Permalink
Browse files

Add non-matching Razor + DTO Models (e.g. exceptions) to Razor ViewPa…

…ge.ModelError and leave Model as null
  • Loading branch information...
1 parent 75ef3bf commit b8ed594dd89e392179094dd95b405701795d70d3 @mythz mythz committed Nov 14, 2012
Showing with 21 additions and 9 deletions.
  1. +9 −0 src/ServiceStack.Razor/ViewPageBase.cs
  2. +12 −9 src/ServiceStack.Razor/ViewPage`1.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Data;
using ServiceStack.CacheAccess;
+using ServiceStack.Common.Web;
using ServiceStack.Html;
using ServiceStack.Messaging;
using ServiceStack.OrmLite;
@@ -10,6 +11,7 @@
using ServiceStack.ServiceHost;
using ServiceStack.ServiceInterface;
using ServiceStack.ServiceInterface.Auth;
+using ServiceStack.ServiceInterface.ServiceModel;
using ServiceStack.WebHost.Endpoints;
namespace ServiceStack.Razor
@@ -42,6 +44,13 @@ public T Get<T>()
public IHttpResponse Response { get; set; }
+ public object ModelError { get; set; }
+
+ public ResponseStatus ResponseStatus
+ {
+ get { return ModelError.ToResponseStatus(); }
+ }
+
private ICacheClient cache;
public ICacheClient Cache
{
@@ -7,8 +7,8 @@
namespace ServiceStack.Razor
{
public abstract class ViewPage<TModel> : ViewPageBase<TModel>
- {
- public HtmlHelper<TModel> Html = new HtmlHelper<TModel>();
+ {
+ public HtmlHelper<TModel> Html = new HtmlHelper<TModel>();
private IViewEngine viewEngine;
public override IViewEngine ViewEngine
@@ -30,18 +30,21 @@ public override Type ModelType
get { return typeof(TModel); }
}
- public override void Init(IRazorViewEngine viewEngine, ViewDataDictionary viewData, IHttpRequest httpReq, IHttpResponse httpRes)
- {
- this.Request = httpReq;
- this.Response = httpRes;
+ public override void Init(IRazorViewEngine viewEngine, ViewDataDictionary viewData, IHttpRequest httpReq, IHttpResponse httpRes)
+ {
+ this.Request = httpReq;
+ this.Response = httpRes;
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)
{
//return this.childSections.ContainsKey(sectionName);
return false;
}
- }
+ }
}

0 comments on commit b8ed594

Please sign in to comment.