Archive for the ‘ASP.NET MVC’ Category

How to write custom action manager for ASP.NET MVC or explenation of how things works there

1. ActionResult it’s acctually the return of standart ASP.NET MVC controller. ActionResult is used to return presentation (view, html, other kinds of presentation) of result returned by action method and write it to ControllerContext response.

    Existing implementations of AcctionResult :

        a) ContentResult : writes to output returned value (converted to string using the toString method of the value).

        b) EmptyResult : writes nothind to output.

        c) HttpUnauthorizedResult : set’s the response code to unauthorized. Writes nothing to output.

        d) JsonResult : serialize returned result to JSON and writes serialized object to Response stream.

        e) RedirectResult : basically redirects a user to another page.

        f) RedirectToRouteResult : redirects to anothere page using routing engine. Example :

            public ActionResult Create(int? categoryId)



                    new RedirectToRouteResult(

                        new RouteValueDictionary(new {controller = “Home”, action = “List”, categoryId = new int?()}));


        g) ViewResultBase : Base class for a result which renders a view. Contains the method FindView which should be overided return ViewEngineResult (?what is ViewEngineResult? explein a bit). There are two existing         specifications :

            I) PartialViewResult : is used to return PartialView

            II) ViewResult : used to return View

            Both of implementation are using strange behaviour. They are calling a method from ViewResultBase class, which is implementation of IViewEngine as well.

    Cool stuff isn’t it?

    Create your own ActionResult – nice example :

2. ActionResult can cont


3. ControllerBase class is basically to be used if you whant you controllers to support following tasks

    ? how ControllerBase is creating? How the ControllerContext is getting there? Because it’s really interesting to have it in your controller method execution process (is it?)

        public ControllerContext ControllerContext { get; set; }

public TempDataDictionary TempData { get; set; }

public IValueProvider ValueProvider { get; set; }

public ViewDataDictionary ViewData { get; set; }


4. Possible implementations of MVC Engine :

    a) Create new ActionResult (ExtActionResult) which will contains exact information about html page to be used, and Mode (possible modes are: List, Single). This one is to be used with Wicket-like style of developing a wicket-style framework.

    b) Result of method execution can be not just a HTML page, but also – it can be preconfigured ExtJS control with a data returned from a method. ? Should be this case specified by some annotatation on method or special attribute in HTML template?



        Section 4:

                    1) Search for a View algorithm :

                        a) Look for a HTML page which corresponds to exact Method which is called from controller

                        b) Look for a HTML page which represents the type which is returned by method. (Can contains 2 presentations : Single and List) If List<?> is returned and List html-template doesnt exists engine should use Single-item template for every returned item.