-
-
Save cvallance/1278674 to your computer and use it in GitHub Desktop.
Pass compositioned data to views
This file contains 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
//You could also use a base controller and put this in there. | |
public class AdminUserViewBagAttribute : ActionFilterAttribute | |
{ | |
public override void OnActionExecuting(ActionExecutingContext filterContext) | |
{ | |
filterContext.Controller.ViewBag.IsCurrentUserAdmin = magic.FigureThatOut(); | |
} | |
} |
This file contains 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 ActionResult ViewPost(string permalink) | |
{ | |
var post = magic.GetPostBy(permalink); | |
var viewModel = new PostView { Post = post }; | |
viewModel.Related = magic.GetContentRelatedTo(post); | |
Return View(viewModel); | |
} | |
public ActionResult Homepage() | |
{ | |
var posts = magic.GetRecentPosts(); | |
var viewModel = new HomepageView { Posts = posts }; | |
viewModel.Related = magic.GetContentRelatedToMany(posts); | |
Return View(viewModel); | |
} | |
//This possibly might be in another class... like a shared controller or something | |
public PartialViewResult LayoutWidgets() | |
{ | |
var viewModel = new LayoutWidgetsView | |
{ | |
Archive = magic.GetArchive(), | |
TagCloud = magic.GetTagCloud() | |
} | |
return View(viewModel); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment