Permalink
Browse files

Fix Request in Partial Views. Don't escape Raw strings

  • Loading branch information...
1 parent 60c89a9 commit ac8b0294db8b51e50b03b48e7c82af1257d5748b @mythz mythz committed Mar 19, 2013
@@ -34,7 +34,7 @@ public override void Init(IRazorViewEngine viewEngine, ViewDataDictionary viewDa
{
this.Request = httpReq;
this.Response = httpRes;
- Html.Init(httpReq, viewEngine, viewData, null);
+ Html.Init(httpReq, httpRes, viewEngine, viewData, null);
this.Model = new DynamicRequestObject(httpReq);
}
@@ -19,6 +19,8 @@ public override void SetState(HtmlHelper htmlHelper)
{
if (htmlHelper == null) return;
+ this.Request = htmlHelper.HttpRequest;
+ this.Response = htmlHelper.HttpResponse;
Html.SetState(htmlHelper);
}
@@ -47,7 +49,7 @@ public override void Init(IRazorViewEngine viewEngine, ViewDataDictionary viewDa
this.Request = httpReq;
this.Response = httpRes;
Html = new HtmlHelper<TModel>();
- Html.Init(httpReq, viewEngine, viewData, null);
+ Html.Init(httpReq, httpRes, viewEngine, viewData, null);
if (viewData.Model is TModel)
this.Model = (TModel)viewData.Model;
else
@@ -85,6 +85,7 @@ public static MethodInfo GetMethod(string methodName)
public bool RenderHtml { get; protected set; }
public IHttpRequest HttpRequest { get; set; }
+ public IHttpResponse HttpResponse { get; set; }
public IViewEngine ViewEngine { get; set; }
public MarkdownPage MarkdownPage { get; protected set; }
@@ -106,6 +107,7 @@ public void SetState(HtmlHelper htmlHelper)
if (htmlHelper == null) return;
HttpRequest = htmlHelper.HttpRequest;
+ HttpResponse = htmlHelper.HttpResponse;
ScopeArgs = htmlHelper.ScopeArgs;
viewData = htmlHelper.ViewData;
}
@@ -122,17 +124,18 @@ public HtmlHelper()
public void Init(MarkdownPage markdownPage, Dictionary<string, object> scopeArgs,
bool renderHtml, ViewDataDictionary viewData, HtmlHelper htmlHelper)
{
- Init(null, markdownPage.Markdown, viewData, htmlHelper);
+ Init(null, null, markdownPage.Markdown, viewData, htmlHelper);
this.RenderHtml = renderHtml;
this.MarkdownPage = markdownPage;
this.ScopeArgs = scopeArgs;
}
- public void Init(IHttpRequest httpReq, IViewEngine viewEngine, ViewDataDictionary viewData, HtmlHelper htmlHelper)
+ public void Init(IHttpRequest httpReq, IHttpResponse httpRes, IViewEngine viewEngine, ViewDataDictionary viewData, HtmlHelper htmlHelper)
{
this.RenderHtml = true;
this.HttpRequest = httpReq ?? (htmlHelper != null ? htmlHelper.HttpRequest : null);
+ this.HttpResponse = httpRes ?? (htmlHelper != null ? htmlHelper.HttpResponse : null);
this.ViewEngine = viewEngine;
this.ViewData = viewData;
this.ViewData.PopulateModelState();
@@ -168,11 +171,11 @@ public string Debug(object model)
return null;
}
- public string Raw(object content)
+ public MvcHtmlString Raw(object content)
{
if (content == null) return null;
var strContent = content as string;
- return strContent ?? content.ToString(); //MvcHtmlString
+ return MvcHtmlString.Create(strContent ?? content.ToString()); //MvcHtmlString
}
public static RouteValueDictionary AnonymousObjectToHtmlAttributes(object htmlAttributes)
@@ -114,7 +114,7 @@ public virtual void Init(IAppHost appHost, MarkdownPage markdownPage, Dictionary
/// </summary>
/// <param name="content"></param>
/// <returns></returns>
- public string Raw(string content)
+ public MvcHtmlString Raw(string content)
{
return Html.Raw(content);
}
@@ -287,6 +287,12 @@ public void Can_get_PartialModel()
Assert200(Host + "/partialmodel", containsItems.ToArray());
}
+ [Test]
+ public void Can_get_RequestPathInfo_in_PartialChildModel()
+ {
+ Assert200(Host + "/partialmodel", Template_PartialModel, ViewPartialChildModel, "PathInfo: <b>/partialmodel</b>");
+ }
+
}
}
@@ -2,4 +2,6 @@
@Html.TextBoxFor(x => x.SomeProperty)
+PathInfo: <b>@base.Request.PathInfo</b>
+
<!--view:PartialChildModel.cshtml-->
@@ -10,6 +10,8 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
+ <h1>@Html.Raw("b&#225;i s&#232;")</h1>
+
@foreach (var item in Model.Items)
{
<div>@Html.Partial("PartialChildModel", item)</div>
@@ -1,4 +1,4 @@
-@inherits ViewPage<List<Rockstar>>
+@model List<Rockstar>
<div id="sidebar">
<h4>Razor Partials with Model</h4>
@@ -7,6 +7,4 @@
}
</div>
-PathInfo: <b>@base.Request.PathInfo</b>
-
<!--view:RazorPartialModel.cshtml-->

0 comments on commit ac8b029

Please sign in to comment.