Skip to content

Commit

Permalink
Fixed some validation in the extension methods
Browse files Browse the repository at this point in the history
The model obviously can't be casted to a string, so the check would always see the value as empty.
  • Loading branch information
abjerner committed May 12, 2015
1 parent e625305 commit fc116dc
Showing 1 changed file with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ public static HtmlString GetTypedGridHtml(this HtmlHelper html, GridDataModel mo
/// <param name="property">The property holding the Grid model.</param>
/// <param name="framework">The framework used to render the Grid.</param>
public static HtmlString GetTypedGridHtml(this HtmlHelper html, IPublishedProperty property, string framework = DefaultFramework) {

// Check whether the property value is empty
if (String.IsNullOrWhiteSpace(property.Value as string)) return new HtmlString(String.Empty);

// Get the property value
GridDataModel value = property.Value as GridDataModel;
if (value == null) return new HtmlString(String.Empty);

// Load the partial view based on the specified framework
return html.Partial("TypedGrid/" + framework, property.Value);
Expand Down Expand Up @@ -130,8 +131,9 @@ public static HtmlString GetTypedGridHtml(this HtmlHelper html, IPublishedConten
IPublishedProperty property = content.GetProperty(propertyAlias);
if (property == null) throw new NullReferenceException("No property type found with alias " + propertyAlias);

// Check whether the property value is empty
if (String.IsNullOrEmpty(property.Value as string)) return new HtmlString(String.Empty);
// Get the property value
GridDataModel value = property.Value as GridDataModel;
if (value == null) return new HtmlString(String.Empty);

// Load the partial view based on the specified framework
return html.Partial("TypedGrid/" + framework, property.Value);
Expand All @@ -145,9 +147,10 @@ public static HtmlString GetTypedGridHtml(this HtmlHelper html, IPublishedConten
/// <param name="html">The instance of <code>HtmlHelper</code>.</param>
/// <param name="framework">The framework used to render the Grid.</param>
public static HtmlString GetTypedGridHtml(this IPublishedProperty property, HtmlHelper html, string framework = DefaultFramework) {

// Check whether the property value is empty
if (String.IsNullOrEmpty(property.Value as string)) return new HtmlString(String.Empty);

// Get the property value
GridDataModel value = property.Value as GridDataModel;
if (value == null) return new HtmlString(String.Empty);

// Load the partial view based on the specified framework
return html.Partial("TypedGrid/" + framework, property.Value);
Expand Down Expand Up @@ -186,8 +189,9 @@ public static HtmlString GetTypedGridHtml(this IPublishedContent content, HtmlHe
IPublishedProperty property = content.GetProperty(propertyAlias);
if (property == null) throw new NullReferenceException("No property type found with alias " + propertyAlias);

// Check whether the property value is empty
if (String.IsNullOrEmpty(property.Value as string)) return new HtmlString(String.Empty);
// Get the property value
GridDataModel value = property.Value as GridDataModel;
if (value == null) return new HtmlString(String.Empty);

// Load the partial view based on the specified framework
return html.Partial("TypedGrid/" + framework, property.Value);
Expand Down

0 comments on commit fc116dc

Please sign in to comment.