ASP.NET MVC3 – DateTime format

You need to set the proper culture in the globalization element of your web.config file for which dd.MM.yyyy is a valid datetime format: <globalization culture=”….” uiCulture=”….” /> For example that’s the default format in german: de-DE. UPDATE: According to your requirement in the comments section you want to keep en-US culture of the application but … Read more

jquery.validate.unobtrusive not working with dynamic injected elements

I tried Xhalent’s approach but unfortunately it wasn’t working for me. Robin’s approach did work and didn’t work. It worked great for dynamically added elements, but if you tried to use JQuery to remove all the validation attributes and spans from the DOM, the validation library still would try to validate them. However, if you … Read more

Using JSON.NET as the default JSON serializer in ASP.NET MVC 3 – is it possible?

I believe the best way to do it, is – as described in your links – to extend ActionResult or extend JsonResult directly. As for the method JsonResult that is not virtual on the controller that’s not true, just choose the right overload. This works well: protected override JsonResult Json(object data, string contentType, Encoding contentEncoding) … Read more

Custom error pages on asp.net MVC3

Here’s an example of how I handle custom errors. I define an ErrorsController with actions handling different HTTP errors: public class ErrorsController : Controller { public ActionResult General(Exception exception) { return Content(“General failure”, “text/plain”); } public ActionResult Http404() { return Content(“Not found”, “text/plain”); } public ActionResult Http403() { return Content(“Forbidden”, “text/plain”); } } and then … Read more

ViewBag, ViewData and TempData

1)TempData Allows you to store data that will survive for a redirect. Internally it uses the Session as backing store, after the redirect is made the data is automatically evicted. The pattern is the following: public ActionResult Foo() { // store something into the tempdata that will be available during a single redirect TempData[“foo”] = … Read more