Created
June 16, 2012 09:38
-
-
Save benfoster/2940739 to your computer and use it in GitHub Desktop.
ASP.NET MVC Controller Scaffolding
This file contains hidden or 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 class MyController { | |
private readonly IViewFactory viewFactory; | |
private readonly ICommandBus bus; | |
public MyController(IViewFactory viewFactory, ICommandBus bus) { | |
this.viewFactory = viewFactory; | |
this.bus = bus; | |
} | |
[HttpGet] | |
public ActionResult List(ListInputModel input) { | |
var model = viewFactory.Create<ListView>(input); | |
return View(model); | |
} | |
[HttpPost] | |
[ValidateModelState] // saves the usual if ModelState.IsValid junk | |
public ActionResult Create(CreateInputModel model) { | |
var cmd = new CreateCommand { | |
Name = model.Name | |
}; | |
bus.Send(cmd); | |
return RedirectToAction("list"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment