Razor actionlink autogenerating ?length=7 in URL?

The ActionLink override you are using matches to the (string linkText, string actionName, Object routeValues, Object htmlAttributes) override. So your “Profile” value is being passed to the routeValues parameter. The behavior of this function with respect to this parameter is to take all public properties on it and add it to the list of route … Read more

Best place to set CurrentCulture for multilingual ASP.NET MVC web applications

I used a global ActionFilter for this, but recently I realized, that setting the current culture in the OnActionExecuting method is too late in some cases. For example, when model after POST request comes to the controller, ASP.NET MVC creates a metadata for model. It occurs before any actions get executed. As a result, DisplayName … Read more

HttpPost vs HttpGet attributes in MVC: Why use HttpPost?

Imagine the following: [HttpGet] public ActionResult Edit(int id) { … } [HttpPost] public ActionResult Edit(MyEditViewModel myEditViewModel) { … } This wouldn’t be possible unless the ActionMethodSelectorAttributes HttpGet and HttpPost where used. This makes it really simple to create an edit view. All the action links just points right back to the controller. If the view … Read more

How to set decimal separators in ASP.NET MVC controllers?

I have just revisited the issue in a real project and finally found a working solution. Proper solution is to have a custom model binder for the type decimal (and decimal? if you’re using them): using System.Globalization; using System.Web.Mvc; public class DecimalModelBinder : DefaultModelBinder { public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { object result … Read more

ASP.NET MVC – HTTP Authentication Prompt

Well, to require basic authentication you need to return 401 status code. But doing that will cause the current authentication module to execute its default unauthorized handler (for forms authentication, this means redirecting to login page). I wrote an ActionFilterAttribte to see if I can get the behaviour you want when there’s no authentication module … Read more