I am in the phase of creating a rendering frame for rendering my models in different formats.
My idea is this:
public class ResidenceRendererShort : IRender<Residence> {
public string Format() {
return "short";
}
public string Render(Residence content) {
return content.Name;
}
}
I can have several of them with different formats, and all of them are injected using Ninject DI into my RenderingService, where I got methods for finding the correct rendering, using methods such as for example. FindRendererFor(Type type, string format)
Now my question is: how can I create a tag in a razor that will use the rendering service and apply the correct render? I studied HtmlHelpers, but they are static methods, and I can not enter RenderingServiceinto this.
I thought I could create something like:
@Model my.namespace.Residence
@Html.RenderObject(Model, "short");
Am I missing something or did someone understand how to do this?
source