Skip to content

Instantly share code, notes, and snippets.

@cvallance
Forked from kenegozi/use_inheritance.cs
Created October 11, 2011 16:56
Show Gist options
  • Save cvallance/1278674 to your computer and use it in GitHub Desktop.
Save cvallance/1278674 to your computer and use it in GitHub Desktop.
Pass compositioned data to views
//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();
}
}
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