I've got a PartialView (@inherits Umbraco.Web.Mvc.UmbracoTemplatePage) that show the children of the current page. All children have a proprerty which value from the Wysiwyg. On this Wysiwyg, the user can select a MacroPartialView.
When I show that PartialView for the first time, everything rendering well. On that page, I have a button to reload the PartialView using $.ajax. When rendering the PartialView using ajax, I get the following error on the children page which content from editor which has a MacroPartialView.
Error : Cannot render a macro when there is no current PublishedContentRequest.
à Umbraco.Web.UmbracoHelper.RenderMacro(String alias, IDictionary`2 parameters) à Umbraco.Web.PropertyEditors.ValueConverters.RteMacroRenderingValueConverter.<>c__DisplayClass7.<RenderRteMacros>b__1(String macroAlias, Dictionary`2 macroAttributes) à Umbraco.Core.Macros.MacroTagParser.ParseMacros(String text, Action`1 textFoundCallback, Action`2 macroFoundCallback) à Umbraco.Web.PropertyEditors.ValueConverters.RteMacroRenderingValueConverter.RenderRteMacros(String source, Boolean preview) à Umbraco.Web.PropertyEditors.ValueConverters.RteMacroRenderingValueConverter.ConvertDataToSource(PublishedPropertyType propertyType, Object source, Boolean preview) à Umbraco.Core.Models.PublishedContent.PublishedPropertyType.ConvertDataToSource(Object source, Boolean preview) à Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedProperty.<.ctor>b__0() à System.Lazy`1.CreateValue() à System.Lazy`1.LazyInitValue() à System.Lazy`1.get_Value() à Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedProperty.<.ctor>b__1() à System.Lazy`1.CreateValue() à System.Lazy`1.LazyInitValue() à System.Lazy`1.get_Value() à Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedProperty.get_Value() à ASP._Page_Views_Partials_NewsListItems_cshtml.Execute() dans c:\CITI_SVN\trunk\SOURCE\Umbraco\7.1.8\Views\Partials\NewsListItems.cshtml:ligne 55
I don't have consider the UmbracoApiController. I'm not sure to understand why il would be better.
public class NewsController : SurfaceController { public ActionResult Search(int idPage, string from, string to) { //Parse date to DateTime dateTo = DateTime.Today; if (!DateTime.TryParse(to, out dateTo))
dateTo = DateTime.Today;
//Parse date from DateTime dateFrom = dateTo.AddMonths(-1); if (!DateTime.TryParse(from, out dateFrom)) dateFrom = dateTo.AddMonths(-1);
//Swap the dates if needed if (dateFrom > dateTo) { DateTime swap = dateFrom; dateFrom = dateTo; dateTo = swap; }
//Get the page IPublishedContent newsPage = Umbraco.Content(idPage);
//Get the list of result List<IPublishedContent> results = newsPage.Children.Cast<IPublishedContent>().Where(news => ((news.GetProperty("newsDate").HasValue && Convert.ToDateTime(news.GetProperty("newsDate").Value) > new DateTime(1900, 1, 1)) ? Convert.ToDateTime(news.GetProperty("newsDate").Value) : news.CreateDate) > dateFrom && ((news.GetProperty("newsDate").HasValue && Convert.ToDateTime(news.GetProperty("newsDate").Value) > new DateTime(1900, 1, 1)) ? Convert.ToDateTime(news.GetProperty("newsDate").Value) : news.CreateDate) < dateTo).ToList();
ViewBag.NewsResult = results;
return PartialView("NewsListItems"); } }
The "results" is put into the ViewBag instead as model of the PartialView. The idPage correspond to a main page "News". All the children are "News" placed under.
no current PublishedContentRequest
Hi,
I've got a PartialView (@inherits Umbraco.Web.Mvc.UmbracoTemplatePage) that show the children of the current page. All children have a proprerty which value from the Wysiwyg. On this Wysiwyg, the user can select a MacroPartialView.
When I show that PartialView for the first time, everything rendering well. On that page, I have a button to reload the PartialView using $.ajax. When rendering the PartialView using ajax, I get the following error on the children page which content from editor which has a MacroPartialView.
Error : Cannot render a macro when there is no current PublishedContentRequest.
à Umbraco.Web.UmbracoHelper.RenderMacro(String alias, IDictionary`2 parameters)
à Umbraco.Web.PropertyEditors.ValueConverters.RteMacroRenderingValueConverter.<>c__DisplayClass7.<RenderRteMacros>b__1(String macroAlias, Dictionary`2 macroAttributes)
à Umbraco.Core.Macros.MacroTagParser.ParseMacros(String text, Action`1 textFoundCallback, Action`2 macroFoundCallback)
à Umbraco.Web.PropertyEditors.ValueConverters.RteMacroRenderingValueConverter.RenderRteMacros(String source, Boolean preview)
à Umbraco.Web.PropertyEditors.ValueConverters.RteMacroRenderingValueConverter.ConvertDataToSource(PublishedPropertyType propertyType, Object source, Boolean preview)
à Umbraco.Core.Models.PublishedContent.PublishedPropertyType.ConvertDataToSource(Object source, Boolean preview)
à Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedProperty.<.ctor>b__0()
à System.Lazy`1.CreateValue()
à System.Lazy`1.LazyInitValue()
à System.Lazy`1.get_Value()
à Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedProperty.<.ctor>b__1()
à System.Lazy`1.CreateValue()
à System.Lazy`1.LazyInitValue()
à System.Lazy`1.get_Value()
à Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedProperty.get_Value()
à ASP._Page_Views_Partials_NewsListItems_cshtml.Execute() dans c:\CITI_SVN\trunk\SOURCE\Umbraco\7.1.8\Views\Partials\NewsListItems.cshtml:ligne 55
Thanks in advance for your help
Can you please explain what you mean by reloading the Partial View with Ajax?
The ajax call is
$.ajax({
type: "GET",
cache: false,
url: "@Url.Action("[MySurfaceControllerAction]", "[MySurfaceControllerName]", new { area = string.Empty })",
data: [MyDataParameters],
dataType: "HTML",
success: function (content) {
$("#[MyControlID]").html(content);
}
});
That ajax code call [MySurfaceControllerAction] from [MySurfaceControllerName] which return PartialView("[MyPartialViewName]")
In a part of the view, I've @Umbraco.Field(page, "htmlContent") which render the content from editor which has a MacroPartialView.
I'hope this help. Please ask if you don't understand.
Ok, I think I see. Could you post the Surface Controller code also?
Have you considered a UmbracoApiController instead for getting the data to JavaScript?
I don't have consider the UmbracoApiController. I'm not sure to understand why il would be better.
public class NewsController : SurfaceController
{
public ActionResult Search(int idPage, string from, string to)
{
//Parse date to
DateTime dateTo = DateTime.Today;
if (!DateTime.TryParse(to, out dateTo))
dateTo = DateTime.Today;
//Parse date from
DateTime dateFrom = dateTo.AddMonths(-1);
if (!DateTime.TryParse(from, out dateFrom))
dateFrom = dateTo.AddMonths(-1);
//Swap the dates if needed
if (dateFrom > dateTo)
{
DateTime swap = dateFrom;
dateFrom = dateTo;
dateTo = swap;
}
//Get the page
IPublishedContent newsPage = Umbraco.Content(idPage);
//Get the list of result
List<IPublishedContent> results = newsPage.Children.Cast<IPublishedContent>().Where(news =>
((news.GetProperty("newsDate").HasValue && Convert.ToDateTime(news.GetProperty("newsDate").Value) > new DateTime(1900, 1, 1)) ? Convert.ToDateTime(news.GetProperty("newsDate").Value) : news.CreateDate) > dateFrom &&
((news.GetProperty("newsDate").HasValue && Convert.ToDateTime(news.GetProperty("newsDate").Value) > new DateTime(1900, 1, 1)) ? Convert.ToDateTime(news.GetProperty("newsDate").Value) : news.CreateDate) < dateTo).ToList();
ViewBag.NewsResult = results;
return PartialView("NewsListItems");
}
}
The "results" is put into the ViewBag instead as model of the PartialView. The idPage correspond to a main page "News". All the children are "News" placed under.
is working on a reply...