The model item passed into the dictionary is of type
'Umbraco_Blog.Models.BlogPost[]', but this dictionary requires a model
item of type 'Umbraco.Web.Models.RenderModel'.
Hi Dave, the problem was that I was passing an array of Blogpost to my view, but the Master.cshtml doesnt accept arrays, it accepts a regular BlogPost object but not an array.
In my blog solution I made before I tried umbraco, I pass an array of BlogPost to my view. It works without a problem because I dont pass anything into my master.cshtml there.
I know I can just pass the parent model Blog, to my view and get the children from the view. But I want to that from my controller, and pass all the blogposts from there.
Now this code below works fine, where I pass the parent of BlogPosts, Blog, into the view.
But I want to be able to work with my custom BlogPosts model in the view. I want to pass all the children of the Blog as my custom BlogPost model to the view. So I can use my properties from my custom BlogPost model something like this
Maybe you can create a custom model called BlogOverview...with one property called BlogPosts...which holds your array...you can create this in your controller and pass it to your view
UmbracoTemplateview inheritance in master.cshtml overrides UmbracoViewPage<customModel> in blog.cshtml
So I need to be able to set the title of my site to the page the visitor is on so in my Master.cshtml I have
Works great.
Now I want to pass my custom blogpost model to my blogview which has Master.cshtml as layout
and in my controller i return a BlogPost[]
But this just gives me this error
If i remove the layout, then it works.
Hi Ado,
How do you pass your model to the view ? Can you post some more code. THat will be easier to help find a solution for your problem.
Dave
Hi Dave, the problem was that I was passing an array of Blogpost to my view, but the Master.cshtml doesnt accept arrays, it accepts a regular BlogPost object but not an array.
In my blog solution I made before I tried umbraco, I pass an array of BlogPost to my view. It works without a problem because I dont pass anything into my master.cshtml there.
I know I can just pass the parent model Blog, to my view and get the children from the view. But I want to that from my controller, and pass all the blogposts from there.
Now this code below works fine, where I pass the parent of BlogPosts, Blog, into the view.
But I want to be able to work with my custom BlogPosts model in the view. I want to pass all the children of the Blog as my custom BlogPost model to the view. So I can use my properties from my custom BlogPost model something like this
}
What would be even better is if there was a way to dynamically set the title and other stuff in my Master.cshtml without using this part
I know i can just pass everything in a viewbag, but then I would need to create the same viewbags in every action.
Maybe you can create a custom model called BlogOverview...with one property called BlogPosts...which holds your array...you can create this in your controller and pass it to your view
Dave
Yea so I created a property for blogposts in Blog, and filled it up dynamically with children in the constructor.
All this is definitely more work, but it allowed me to keep logic out of the view, and create pagination with two simple if statements in the view.
Will there ever be a problem, if a property I have in my Blog model, doesnt exist as a property in Umbraco Document Type Blog ?
When working with strongly typed models it's maybe a good idea to have a look at Zbu Models builder or Ditto
Hi Ado,
Firstlly create custom model for fetch data from Umbraco database
Please try this in razor page for inherit data from custom model
hope this help,
Regards, Samira
is working on a reply...