How to scaffold views with custom ViewModel?

Mar 16, 2012 at 11:45 PM

I use custom ViewModels in all my views.  Is there a way of scaffolding custom view templates that pick up my viewmodel?  At the moment it doesn't detect it unless I'm doing something wrong.

Here's an example of my Edit Razor view:

@model ESMvcDemo.Mvc.ViewData.CategoriesViewData

    ViewBag.Title = @Model.PageTitle;


@using (Html.BeginForm()) {

        <div class="editor-label">
            @Html.LabelFor(model => model.Categories.CategoryName)
        <div class="editor-field">
            @Html.EditorFor(model => model.Categories.CategoryName)
            @Html.ValidationMessageFor(model => model.Categories.CategoryName)

        <div class="editor-label">
            @Html.LabelFor(model => model.Categories.Description)
        <div class="editor-field">
            @Html.EditorFor(model => model.Categories.Description)
            @Html.ValidationMessageFor(model => model.Categories.Description)

            <input type="submit" value="Save" />

    @Html.ActionLink("Back to List", "Index")

This line in the Index.cs.t4 always returns null:

<# var viewDataType = (EnvDTE.CodeType) Model.ViewDataType; #>

Any suggestions on how to create a custom view template for this?