Thursday, April 21, 2011

Can the controller code generation template be changed?

In Visual Studio when you add a new controller to your MVC application some macro creates a file with methods like:

//
// GET: /Thing/Details/5

public ActionResult Details(int id)
{
    return View();
}

I want my methods to look like:

/// <example>GET: /Thing/Details/XXX...</example>
public ActionResult Details(Guid id)
{
    return View(Repository.GetItem<Thing, Guid>(id, "Id"));
}

The main differences are standard notation for the comments with the two redundant lines removed and I use unique identifiers rather than integers for my id's. If possible, I'd like the code to pass my Model to the view to also be generated.

Is there a built in mechanism that will let me control the code template that is used?

From stackoverflow
  • I think David Hayden has a solution for you here. Blog Post

    Hope that hleps,

    Dan

    grenade : Beautiful, thanks!

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.