Using @inherits UmbracoTemplatePage<IPublishedContent> and Custom model
I am trying to use a @inherits UmbracoTemplatePage
I dont know if this is possible?? What i am trying to do, is make a partial view, that takes both CMS content therefor IpublishedContent, and database data, and therefor also use UmbracoWebsite.Models.Coffee
Now it says CS0117: 'umbraco.item' indeholder ikke en definition af 'Link'. and the second part is, when i comment it out, it want show my content in these lines
Overall I'm not quite sure what you're looking for, and it appears you have something working nevertheless!
The original question you posted sounds like you're looking for the RenderModel capabilities that Umbraco offers where the IPublishedContent model that comes back from the CMS can be extended with custom properties.
namespace WebAPITestConnectionToOtherSite.Models
{
public class Coffee : RenderModel, IEnumerable<Coffee>
{
public Coffee(IPublishedContent content) : base(content) { }
public int Id { get; set; }
public string Name { get; set; }
public int Volume { get; set; }
public int CompanyId { get; set; }
public Company Company { get; set; }
public IEnumerator<Coffee> GetEnumerator()
{
throw new NotImplementedException();
}
IEnumerator IEnumerable.GetEnumerator()
{
throw new NotImplementedException();
}
}
public class Company
{
public int Id { get; set; }
public string CompanyName { get; set; }
}
}
My Controller method is this.
public ActionResult GetCoffee(RenderModel model)
{
var apiCall = $"Home/Coffee";
var model1 = GetFromAPI<List<Coffee>>(apiCall);
model1.And(model);
return PartialView("GetCoffee", model1);
}
When i try to render my view it saying
@Html.Action("GetCoffee()" , "MySurface")
i get an exception saying System.InvalidOperationException: 'No route in the route table matches the supplied values.'
My troubles is that i have to get data via an API call, return it. Add it to a view, with umbraco content and my custom model content aswell. I need to be able to insert my data wherever i want..
<div>
<div>Custom model content</div>
<div>Umbraco content</div>
<div>Custom model content</div>
</div>
Likewise, you probably want to be returning a PartialViewResult from the GetCoffee() method - but not a biggie.
Is there any chance you can post a bit more detail about the main Razor view you have (where you are calling the Html.Action), to try and understand a bit better where you're coming from?
In the meantime - give that a try and let me know how you get on.
Using @inherits UmbracoTemplatePage<IPublishedContent> and Custom model
I am trying to use a @inherits UmbracoTemplatePage
I dont know if this is possible?? What i am trying to do, is make a partial view, that takes both CMS content therefor IpublishedContent, and database data, and therefor also use UmbracoWebsite.Models.Coffee
My Partial View looks like this
The first two
<div class="ta-center col-md-4">
shows cms content with IpublishedContentAnd the last
<div class="ta-center col-md-4">
should show content using my UmbracoWebsite.Models.Coffee modelAnyone have any ideas?
I might be worth note that i am using a surfaceController, which i call from my master.cshtml @Html.Action("GetCoffee", "UmbracoSurface")
Hi Magnus,
I seem to think you can only have one
@imports
statement.But, you should be able to access your parent IPublishedContent type via:
@Umbraco.AssignedContentItem
in the partial view.Nik
Hey Nik, so this is what i got.
Now it says CS0117: 'umbraco.item' indeholder ikke en definition af 'Link'. and the second part is, when i comment it out, it want show my content in these lines
Its just blank.
So to sum up my very confusing message
I cant find link when i try to do a foreach on a umbraco item, and @Umbraco.AssignedContentItem.GetPropertyValue, doesn't show any data on my page
Just for further notice. The solution become that i created a partial view macro the used @model, and parsed it as a @Html.Action
Hey Magnus,
Overall I'm not quite sure what you're looking for, and it appears you have something working nevertheless!
The original question you posted sounds like you're looking for the RenderModel capabilities that Umbraco offers where the IPublishedContent model that comes back from the CMS can be extended with custom properties.
There's some great documentation on this functionality here: https://our.umbraco.com/documentation/Reference/Routing/custom-controllers#returning-a-view-with-a-custom-model which steps you through extending the base model and inheriting in on the page, thus allowing the custom properties I think you were looking for :)
Cheers,
Laura
Hey Laura. I can't seem to get it to work.
This is my Model
}
My Controller method is this.
When i try to render my view it saying
i get an exception saying System.InvalidOperationException: 'No route in the route table matches the supplied values.'
My troubles is that i have to get data via an API call, return it. Add it to a view, with umbraco content and my custom model content aswell. I need to be able to insert my data wherever i want..
Hey Magnus,
You probably want your @Html.Action call to your MySurfaceController to look a bit more like this:
Likewise, you probably want to be returning a PartialViewResult from the GetCoffee() method - but not a biggie.
Is there any chance you can post a bit more detail about the main Razor view you have (where you are calling the Html.Action), to try and understand a bit better where you're coming from?
In the meantime - give that a try and let me know how you get on.
Cheers,
Laura
Hi Magnus, you should be able to get content from Umbraco in this case by doing:
in your constructor, right?
And then just have the view inherit from your model like:
is working on a reply...