Last active
December 20, 2015 12:59
-
-
Save mattbrailsford/6134978 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ListingPageController : RenderMvcController | |
{ | |
public override ActionResult Index(RenderModel model) | |
{ | |
// Do stuff here | |
return CurrentTemplate(new ListingViewModel(model) | |
{ | |
CurrentListing = listing | |
}); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@using MyNamespace.Web.ViewModels | |
@inherits Umbraco.Web.Mvc.UmbracoViewPage<ListingViewModel> | |
@{ | |
Layout = "Master.cshtml"; | |
} | |
<h1>@Model.CurrentListing.Name</h1> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A issue with Umbraco hijacked routes and custom view models | |
// means our viewmodel currently has to inherit from RenderModel | |
public class ListingViewModel : RenderModel | |
{ | |
public ListingViewModel(RenderModel model) | |
: this(model.Content, model.CurrentCulture) | |
{ } | |
public ListingViewModel(IPublishedContent content, CultureInfo culture) | |
: base(content, culture) | |
{ } | |
public ListingViewModel(IPublishedContent content) | |
: base(content) | |
{ } | |
public Listing CurrentListing { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you return a view like you do in normal Mvc, then it's perfectly fine to return a custom model that doesn't inherit from RenderModel. But then you have to specify the view yourself, which I'm guessing you would like to avoid?
At least, I have that working perfectly.