Skip to content

Instantly share code, notes, and snippets.

@mortenbock
Created August 1, 2013 21:12
Show Gist options
  • Save mortenbock/6135379 to your computer and use it in GitHub Desktop.
Save mortenbock/6135379 to your computer and use it in GitHub Desktop.
Custom viewmodel in Umbraco
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>_Layout</title>
</head>
<body>
<div>
@RenderBody()
</div>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace UmbSample.Models
{
public class MyModel
{
public string Title { get; set; }
}
}
@inherits UmbracoViewPage<UmbSample.Models.MyModel>
@{
Layout = "_Layout.cshtml";
}
Testing: @Model.Title
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Umbraco.Web.Mvc;
using UmbSample.Models;
namespace UmbSample.Controllers
{
public class umbHomepageController : Umbraco.Web.Mvc.RenderMvcController
{
public override System.Web.Mvc.ActionResult Index(Umbraco.Web.Models.RenderModel model)
{
return CurrentTemplate(new MyModel() { Title = model.Content.Name });
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment