I am using a castle windsor factory to instantiate an object based on the request url.
Something like:
public FooViewModel Get()
{
if (HttpContext.Current == null)
{
return new FooViewModel();
}
var currentContext = new HttpContextWrapper(HttpContext.Current);
// resolve actual view model.
In some cases, I actually want to throw a 404 and stop the request, currently like:
throw new HttpException(404, "HTTP/1.1 404 Not Found");
currentContext.Response.End();
However the request doesn't end and it still hits the Action and tries to resolve the view?
My Controller would look something like this:
public class HomeController : Controller
{
public FooViewModel Foo { get; set; }
public ActionResult Index()
{
ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
return View();
}
Am I thinking about this all wrong? Or is there a way I can achieve this?
The alternative I was thinking of is an attribute on the action to check the state of the Foo property?