November Happy Hour will be moved to Thursday December 5th.

How to get full refresh to work in MVC razor

Vote:
 

I have tried to get full refresh to work with MVC and razor the way episerver suggests but so far no luck. I will write below what I did and also what workaround I used to get it to work.

I have a boolean property on one of my blocks that adds a border. What I wanted to achieve was to make a preview page for the block that updated the visuals of the block when the value of that Boolean changed. This required a page refresh then the property changed. I tried following this example in the episerver sdk http://sdkbeta.episerver.com/SDK-html-Container/?path=/SdkDocuments/CMS/7/Knowledge%20Base/Developer%20Guide/Content/Pages%20and%20Blocks/How%20To/Edit%20hints%20in%20MVC.htm&vppRoot=/SdkDocuments//CMS/7/Knowledge%20Base/Developer%20Guide/ .

This is what I did.
In the controller I added AddFullRefreshFor for the border Boolean.

var editingHints = ViewData.GetEditHints<ViewModel,EpiBlock>();
               
editingHints.AddFullRefreshFor(p=>p.Border);

    

In the view I added the full refresh method and the property.

@Html.FullRefreshPropertiesMetaData()
Border: @Html.PropertyFor(m=>m.EpiData.Border)

    

This did not work.
It looks like there is a bug in the FullRefreshPropertiesMetaData method.

public static MvcHtmlString FullRefreshPropertiesMetaData<TModel>(this HtmlHelper<TModel> helper)
    {
      if (RequestContextExtension.GetContextMode(helper.ViewContext.RequestContext) == ContextMode.Edit)
      {
        IList<EditHint> list = helper.ViewData[ViewDataKeys.FullRefreshProperties] as IList<EditHint>;
        if (list != null && list.Count > 0)
          return PropertyExtensions.FullRefreshPropertiesMetaData((HtmlHelper) helper, Enumerable.ToArray<string>(Enumerable.Select<EditHint, string>((IEnumerable<EditHint>) list, (Func<EditHint, string>) (e => e.ContentDataPropertyName))));
      }
      return MvcHtmlString.Empty;
    }

    

The helper.viewdata returns a list of strings that can't be cast to a IList<EditHint> and thus it will always be null.


SOLUTION

The solution that I did was to write my own extension method that solves this.

public static MvcHtmlString FullRefreshPropertiesMetaDataThatActuallyWorks<TViewModel>(this HtmlHelper<TViewModel> me)
         {
             var refreshProperties = me.ViewData[ViewDataKeys.FullRefreshProperties] as IEnumerable<string>;
             if(refreshProperties != null)
             {                 
                 return me.FullRefreshPropertiesMetaData(refreshProperties.ToArray());
             }
             return MvcHtmlString.Empty;
         }

    And call this method in the view instead.

#65719
Feb 06, 2013 15:45
Vote:
 

Hi

That sure looks like a bug. I'll add it to our bug tracker.

Thanks for reporting this, and also for providing a work around.

Update:
Bug registered as: #95628: Not possible to add full refresh using the FullRefreshPropertiesMetaData extension method

Regards

Per Gunsarfs
EPiServer Development Team

#65724
Edited, Feb 06, 2013 16:35
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.