Adam Gordon Bell

Naked Objects MVC - exposing a repository method as a get

October 9, 2010 ยท c# NakedObjectsFramework

If you would like to expose the results of an entity framework call as the index page or any other get based url using naked object mvc, a custom controller is required.

public class HomeController : CustomController
    {
        public ActionResult Index()
        {
            var siteRep = FrameworkHelper.GetService<SimpleRepository<Site>>();
            return InvokeAction(siteRep, โ€œAllโ€, new FormCollection(), โ€œโ€, โ€œStandaloneTableโ€);
        }
    }

Here the home controller will return the StandaloneTable view of the All() method on SimpleRepository.