🇵🇸 Call for a #CeasefireNOW 🇵🇸

Act Now

Html.EditorFor, Model Property vs RouteData Value

The ASP.NET MVC team made our lives easier when they created the Html editor extension method Html.EditoFor(); you just pass the model property and it creates the right editor, filling it with the property’s value…but not always! Let’s consider that we have the conventional route definition: routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults ); and this simple action method: ...

May 13, 2012 Â· Emad Alashi

How Html.Action() Work

Let’s take the example: @Html.Action("Latest", "Episode") What this will do is to invoke the “Latest” action method in the “Episode” controller. But what really happens behind the scenes is NOT a direct invoke; it will actually start from the beginning of the ASP.NET MVC execution pipeline using “Latest” and “Episode” as Route values for the keys “action” and “controller” respectively. This means that you should pay very good attention to your Routes definition in the Application_Start() in Global.asax; Html.Action() will try to match the best route in your defined routes according to the RouteValueDictionary created above (action and controller) along with any additional route values provided in the overload. ...

March 23, 2012 Â· Emad Alashi

QueryString in Routing and Model Binding in ASP.NET MVC

In a nutshell, a query string will not be part of the RouteData dictionary in the routing process, yet it will affect the route matching. On the other hand, when Model Binding takes place, query string will be used to bind to the parameters of the action method, unless there is an item in route data with the same key. Now the details. Let us consider this ASP.NET MVC application. We have an action method: ...

January 13, 2012 Â· Emad Alashi