c# - Cannot convert type 'Umbraco.Core.Dynamics.DynamicNull' to 'Umbraco.....' - Umbraco v6 -
i've looked @ couple of similar errors regarding ipublishedcontent
(yes know different object i'm using) in umbraco, , they've said it's been fixed since 4.11.7 - however, i'm using v6 that's not case.
my code worked until threw in coalesce:
worked:
dynamicpublishedcontent countryfolder = umbraco.media(currentpage.getproperty("contestmediafolder").value.tostring());
no longer works:
dynamicpublishedcontent countryfolder = !string.isnullorempty(contestfolder) ? umbraco.media(currentpage.getproperty("contestmediafolder").value.tostring()) : umbraco.media(contestfolder);
cannot convert type 'umbraco.core.dynamics.dynamicnull' 'umbraco.web.models.dynamicpublishedcontent'
i have (2) controllers calling same code, 1 controller hit on page load, other api controller. reason i'm passing in variable, contestfolder
, string
, since method returns list. in method call, i'm passing in string.empty
, run first line.
i've tried:
- replacing typed object,
dynamicpublishedcontent
var
. - passing in
int
ratherstring
method (contestfolder
int). - casting both returns on
umbraco.media()
dynamicpublishedcontent
- instead of using
dynamicpublishedcontent
, useipublishedcontent
object.
i switched out how retrieved folder. singled out reason, , it's b/c if regardless if 2nd coalesce hits, umbraco attempts retrieve folder, , if it's null, returns error,
cannot convert type 'umbraco.core.dynamics.dynamicnull' 'umbraco.web.models.dynamicpublishedcontent'
therefore, have pass actual media id (that's valid) umbraco.media()
method, or you'll have error returned you.
public override actionresult index(rendermodel model) { var entries = this.getcontestentries(this.getcountryfolder(currentpage.getproperty("contestmediafolder").value.tostring())); return base.index(model); } public dynamicpublishedcontent getcountryfolder(string countryfolder) { return (dynamicpublishedcontent)umbraco.media(countryfolder); } public list<war2015contestmodel> getcontestentries(dynamicpublishedcontent countryfolder) { ..... // code omitted }
Comments
Post a Comment