Model.MediaById throws exception when node deleted and then removed from the recycle bin
Hi everyone,
Sorry if this is a duplicate but searching the forum hasn't resulted in finding an answer to this.
I've recently developed a project using pure Razor and everything was fine until a bug was raised by the client. The functionality is to select multiple media nodes using uComponents Multi Node Picker and output these using Razor, pretty simple stuff.
The first issue arises when a media node is deleted and put in the recycle bin. This results in no change to the multi node picker content and the front end of the site also remains un-changed because Model.MediaById returns the node even if it's in the recycle bin. This was resolved by checking if the ParentId was -21, not ideal but a fix.
The second issue arises when the deleted node is then removed from the recycle bin. This results in MediaById querying for the deleted ID and throwing an exception. Currently I'm using a try/catch which I'm not overly happy about and it seems like an issue that should have cropped up elsewhere.
I'd be interested to know if this is resolved in an update or if I'm simply doing something wrong.
I just had this problem as well. A page was referencing the ID of an image that had been deleted, so MediaById threw an exception. Shouldn't this method return false instead of throwing an exception? Seems perfectly logical to me that if you ask the MediaById to fetch you an image with a certain ID, and that image does not exist, then it returns false, as in, "Sorry, there is no such image."
Gotten around this with a try/catch for now, but does one seriously need to run a try/catch every time you want to use an image through Razor????
Model.MediaById throws exception when node deleted and then removed from the recycle bin
Hi everyone,
Sorry if this is a duplicate but searching the forum hasn't resulted in finding an answer to this.
I've recently developed a project using pure Razor and everything was fine until a bug was raised by the client. The functionality is to select multiple media nodes using uComponents Multi Node Picker and output these using Razor, pretty simple stuff.
The first issue arises when a media node is deleted and put in the recycle bin. This results in no change to the multi node picker content and the front end of the site also remains un-changed because Model.MediaById returns the node even if it's in the recycle bin. This was resolved by checking if the ParentId was -21, not ideal but a fix.
The second issue arises when the deleted node is then removed from the recycle bin. This results in MediaById querying for the deleted ID and throwing an exception. Currently I'm using a try/catch which I'm not overly happy about and it seems like an issue that should have cropped up elsewhere.
I'd be interested to know if this is resolved in an update or if I'm simply doing something wrong.
Any help would be greatly appreciated.
Cheers
Jamie.
I just had this problem as well. A page was referencing the ID of an image that had been deleted, so MediaById threw an exception. Shouldn't this method return false instead of throwing an exception? Seems perfectly logical to me that if you ask the MediaById to fetch you an image with a certain ID, and that image does not exist, then it returns false, as in, "Sorry, there is no such image."
Gotten around this with a try/catch for now, but does one seriously need to run a try/catch every time you want to use an image through Razor????
Have filed a bug report on it here: http://umbraco.codeplex.com/workitem/30567
is working on a reply...