I am fairly new to Umbraco and Razor, and I keep seeing snippets of code like this which I have tried to use, but do not understand whether it is code that can should be placed in a template, partial view, macro? I'd be grateful if someone could explain as I either get error messages telling me @Model cannot be used or the @inherits line is not allowed etc.
@inherits umbraco.MacroEngines.DynamicNodeContext
enter code here`@{
var last = Model.DescendantsOrSelf().Last();
if (last != null && Model.Id != last.Id)
{
Response.Redirect(last.Url);
}
}
Hi Simon. Going off the top namespace, I'd say that looks like a Macro Partial. There's more information about Macro Razor scripts in the documentation section. Thanks, Dan.
Is this template code or macro code?
I am fairly new to Umbraco and Razor, and I keep seeing snippets of code like this which I have tried to use, but do not understand whether it is code that can should be placed in a template, partial view, macro? I'd be grateful if someone could explain as I either get error messages telling me @Model cannot be used or the @inherits line is not allowed etc.
Thanks Simon
Hi Simon. Going off the top namespace, I'd say that looks like a Macro Partial. There's more information about Macro Razor scripts in the documentation section. Thanks, Dan.
Awesome thanks Dan. I thought it was Partial View Macro code.
When I create a partial view macro via Umbraco backend it uses this
Can I just replace this line with this line:
Is this ok to do as you can only inherit from on library etc?
is working on a reply...