Umbraco v9 - question about GetModelPropertyType method on a generated model (document type) in v9
I'm following along with the "Surface Controller" videos on youtube from the official YT channel. I'm on the "Surface Controllers: Creating content" video.
So far the code looks like:
[HttpPost]
[ValidateUmbracoFormRouteString]
public IActionResult Submit(ArticleModel model)
{
if (!ModelState.IsValid)
{
return CurrentUmbracoPage();
}
var contentService = Services.ContentService;
var parentId = new Guid("4505b81c-0dad-4b6b-bf69-daad24ba4524");
var article = contentService.Create(model.Title, parentId, Article.ModelTypeAlias);
contentService.SaveAndPublish(article);
return RedirectToCurrentUmbracoPage();
}
Everything works fine so far. However the next part of the video you're supposed to get the IPublishedPropertyType of the Summary property from the Article class from Umbraco.Cms.Web.Common.PublishedModels.
That code is supposed to look like:
var summaryProperty = Article.GetModelPropertyType(d => d.Summary);
However, when I try to do this, the GetModelPropertyType expects an IPublishedSnapshotAccessor type to be it's first parameter.
What do I do? Is there another method to call somewhere? I know the video is using v8 so is there a way to do this in v9? Anyway's thanks to anyone who read this and I hope this helps someone else in the future.
Umbraco v9 - question about GetModelPropertyType method on a generated model (document type) in v9
I'm following along with the "Surface Controller" videos on youtube from the official YT channel. I'm on the "Surface Controllers: Creating content" video.
So far the code looks like:
Everything works fine so far. However the next part of the video you're supposed to get the
IPublishedPropertyType
of theSummary
property from theArticle
class fromUmbraco.Cms.Web.Common.PublishedModels
.That code is supposed to look like:
However, when I try to do this, the GetModelPropertyType expects an
IPublishedSnapshotAccessor
type to be it's first parameter.What do I do? Is there another method to call somewhere? I know the video is using v8 so is there a way to do this in v9? Anyway's thanks to anyone who read this and I hope this helps someone else in the future.
You actually need to do exactly as stated in the message. The method now requires an instance of IPublishedSnapShotAccessor
Use dependency injection to add the IPublishedSnapShotAccessor to your class
So you get something like this:
Now you have the _snapshotAccessor available for usage. The GetModelPropertyType method requires it, so you can add it:
Done ! :-)
Thank you sooooo soo much Ambert!
is working on a reply...