Created
July 30, 2012 00:01
-
-
Save toddpi314/3202702 to your computer and use it in GitHub Desktop.
Lightning_BaseController
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
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