You will find that most of the time you will get away with not having to create Macros at all as you can either write the Razor directly in the template or include a Razor Partial View. Macros with MVC will most likely only be needed when you want to allow editors to insert functional blocks into the rich text editor or when you need to include a form (Child Action Macro) in the page.
Sounds like Partial Views should make a good go-to alternative for code that won't be accessed by the editors. But I'm curious, will the same caching abilities apply to partial views? With Marcros it's possible to catch the result of pages even on query string driven pages. In a search routine for a large site this kind of caching is invaluable, will the same apply to partials?
I'm not completely sure of caching based on the querystring, but hopefully with a bit of playing around you can achieve when was possible in v4. FOr others not aware of this, Matt Brailsford has an excellent post on caching by querystring:
I'd found the cache setting for Partials in the refrecene but it was the following statement that gave me pause;
"So you can specify to cache by member and/or by page and also specify additional view data to your partial view. HOWEVER, if your view data is dynamic (meaning it could change per page request) the cached output will still be returned, this same principle goes for if the model you are passing in is dynamic. Please be aware of this as if you have a different model or viewData for any page request, the result will be the cached result of the first execution."
I read that to mean that although you can pass in viewdata IE
@Html.Partial("YourPartialName", new ViewDataDictionary{{ "age",33},{"name","peter"}})
If that data changes the cache will still return the original view render rather than anything changed meaning. For instance if you where to use query string data when that value changes the view output from the cache wouldn't reflect that change.
I'm certainly going to experiment but it looks to me that I'll have to stick to Macro rendering for those routines which are dependant on dynamic data for the time being.
From this issue report I see that regular razor macros will become obsolete and are now just for backward compatibility, whereas Partial View Macro will become the new standard for passing parameteres around, etc.
V6: What are the differences between Partial View Macro File and a Razor Macro?
Hello all,
I wanted to know if anyone knew the differences between using a Partial View Macro and a Razor Scripting Macro in Umbraco V6?
What are the benefits of using one over the other, as to me at the moment I don't see how to make the best use of out it?
Cheers,
Warren
Were you able to get any insite on this subject Warren? I'm curious also.
I was just wondering the very same thing. Could anyone shed any light on what the best practice going forward should be?
Same question here
You will find that most of the time you will get away with not having to create Macros at all as you can either write the Razor directly in the template or include a Razor Partial View. Macros with MVC will most likely only be needed when you want to allow editors to insert functional blocks into the rich text editor or when you need to include a form (Child Action Macro) in the page.
Source: http://umbraco.com/follow-us/blog-archive/2012/10/30/getting-started-with-mvc-in-umbraco-410.aspx
Hi Barry,
Sounds like Partial Views should make a good go-to alternative for code that won't be accessed by the editors. But I'm curious, will the same caching abilities apply to partial views? With Marcros it's possible to catch the result of pages even on query string driven pages. In a search routine for a large site this kind of caching is invaluable, will the same apply to partials?
Hey Drew. Its a good question. You can use the
@Html.CachedPartial("MyPartialName", new MyModel(), 3600
syntax. Check out the details in the documentation:
http://our.umbraco.org/Documentation/Reference/Mvc/partial-views
I'm not completely sure of caching based on the querystring, but hopefully with a bit of playing around you can achieve when was possible in v4. FOr others not aware of this, Matt Brailsford has an excellent post on caching by querystring:
http://blog.mattbrailsford.com/2011/02/01/caching-an-umbraco-macro-by-querystring-parameter/
Hi Barry,
I'd found the cache setting for Partials in the refrecene but it was the following statement that gave me pause;
"So you can specify to cache by member and/or by page and also specify additional view data to your partial view. HOWEVER, if your view data is dynamic (meaning it could change per page request) the cached output will still be returned, this same principle goes for if the model you are passing in is dynamic. Please be aware of this as if you have a different model or viewData for any page request, the result will be the cached result of the first execution."
I read that to mean that although you can pass in viewdata IE
If that data changes the cache will still return the original view render rather than anything changed meaning. For instance if you where to use query string data when that value changes the view output from the cache wouldn't reflect that change.
I'm certainly going to experiment but it looks to me that I'll have to stick to Macro rendering for those routines which are dependant on dynamic data for the time being.
Hi guys!
Is there any way to "release the cache"? I have to restart my app pool for every change i make to my partials right now, it's quite tedious!
Publishing (any node) is supposed to release the cache I seem to remember.
From this issue report I see that regular razor macros will become obsolete and are now just for backward compatibility, whereas Partial View Macro will become the new standard for passing parameteres around, etc.
Src: http://issues.umbraco.org/issue/U4-1681
is working on a reply...