Skip to content

Instantly share code, notes, and snippets.

@toddpi314
Created July 30, 2012 00:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toddpi314/3202702 to your computer and use it in GitHub Desktop.
Save toddpi314/3202702 to your computer and use it in GitHub Desktop.
Lightning_BaseController
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using LightningMVC.Views;
using Views;
namespace LightningMVC.Controllers
{
public abstract class BaseController : Controller, IViewController
{
public ActionResult ResolveView<T>(string view) where T : CoreViewModel
{
var viewModel = (T)ViewModelLocator.Locate(view);
var valid = this.TryUpdateModel<T>(viewModel);
viewModel.ViewController = this;
viewModel.IsAjaxRequest = this.Request.IsAjaxRequest();
viewModel.OnDataSet();
if (valid)
{
viewModel.OnValidated();
}
if (viewModel.Error != null)
{
this.ModelState.AddModelError("", viewModel.Error);
}
if (viewModel.ActionResult == null)
return View(view, viewModel);
else
return viewModel.ActionResult;
}
public ActionResult NavigateToView(string controller, string view, object args)
{
return RedirectToAction(view, controller, args);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment