Hi Thanh, are you using a Mvc cshtml template that starts with @inherits Umbraco.Web.Mvc.UmbracoViewPage or @inherits Umbraco.Web.Mvc.UmbracoTemplatePage or are you using a Razor macro in a WebForms .master template where the Razor cshtml would start with @inherits umbraco.MacroEngines.DynamicNodeContext?
Ok, so I don't understand, why don't you use a partial view rather than trying to use a Macro? Can you post the contents of /macroScripts/scripts.cshtml I'm sure we can convert it to a Partial...?
That should work fine, but It would be better to convert the existing file to a partial view. If you post the code I'm sure we can help convert it for you.
I have converted the first part for you to consider if it's worth doing it for the whole file
Main change for conversion is Model.NodeById becomes Umbraco.TypedContent and as I've used Strongly Typed rather than dynamic model you need to use Model.GetPropertyValue
var root = Umbraco.TypedContent(Model.Path.Split(',')[1]);
var blog = Umbraco.TypedContent(Model.Id);
var parentNode = Umbraco.TypedContent(blog.Parent.Id);
// Get blogger
var blogger = Umbraco.TypedContent(0);
foreach (var item in root.Descendants("blogger"))
{
if (item.GetPropertyValue<string>("loginName").ToLower() == blog.GetPropertyValue<string>("creatorName").ToLower())
{
blogger = item;
break;
}
}
string dns = "http://" + Request.Url.Authority;
var bloggerUrl = dns + "/blogsbyblogger?name=" + blogger.GetPropertyValue<string>("loginName");
var urlRss = dns + "/bloggerrss?name=" + blogger.GetPropertyValue<string>("loginName");
var currentUrl = dns + blog.Url;
Need to help @Umbraco.RenderMacro parameter
I have code render marco in template aspx as below:
<umbraco:Macro ID="javascrpt" alias="javascrpt" runat="server" FileLocation="~/macroScripts/scripts.cshtml"/>
Now, I'm using template cshtml. How to render this macro.
Please help me!
Hi Thanh,
I'm not sure what your parameter is there, but here is how you can render a Macro from a Mvc view:
More info here
Jeavon
Hi Jeavon Leopold!
Thanks for you help!
My problem as following:
- I have file "script.cshtml" in "Scripting Files" folder.
- I want render this file in template cshtml.
Can you hep me!
Hi Thanh, are you using a Mvc cshtml template that starts with
@inherits Umbraco.Web.Mvc.UmbracoViewPage
or@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
or are you using a Razor macro in a WebForms .master template where the Razor cshtml would start with@inherits umbraco.MacroEngines.DynamicNodeContext
?Hi Jeavon Leopold. I'm using MVC cshtml template start with @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
Ok, so I don't understand, why don't you use a partial view rather than trying to use a Macro? Can you post the contents of /macroScripts/scripts.cshtml I'm sure we can convert it to a Partial...?
try this
Hi Ali! I have try. It don't work. Thank you!
Hi Jeavon. That is a good solution for me. Because I got source form old developer. I'm switching from Webform to MVC. Thank you!
My problem have been solved. This Scripting File doesn't have Macro. I create new Macro and access to Scripting File
Hi Thanh,
That should work fine, but It would be better to convert the existing file to a partial view. If you post the code I'm sure we can help convert it for you.
Jeavon
Hi Jeavon. I have many Scripting Files like this. One of them here:
I have somr problem with Surface Controller and Partial View. Can I post question in this topic?
Hi Thanh,
I have converted the first part for you to consider if it's worth doing it for the whole file
Main change for conversion is Model.NodeById becomes Umbraco.TypedContent and as I've used Strongly Typed rather than dynamic model you need to use Model.GetPropertyValue
Hope that's helpful to you,
Jeavon
Thank you Jeavon!
This is helpful knowledge.
is working on a reply...