Using TypeScript in ASP.NET 5

As we can read on the TypeScript it lets you write JavaScript the way you really want to. And guess what – you can do it in Visual Studio 2015! Visual Studio TypeScript support two different modes: File Scope: in this mode TypeScript files opened in Visual Studio Code are treated as independent units. As long as a file a.ts doesn't reference a file b.ts explicitly (either using…

By Dawid on (tags: asp.net 5, mvc, TypeScript, visual studio, vs, categories: code, web)

Web Api: custom binding with AutoMapper

In Web Api 2.0 and MVC5 you can only pass: int, bool, double etc.., TimeSpan, DateTime, Guid, decimal, and string values in URI. For any complex type having lists or other complex object within you have to pass serialized JSON/XML in the request body. But what If we want use such complex type from URI? Then read on… What is binding? Binding is a mechanism used by the Web Api to…

By Piotr on (tags: automapper, mvc, Web API, categories: code)

MVC custom error pages

Long story short – mvc does not handle custom error pages in a way that could be described as ‘even close to correct’. But if you need to fulfill a requirement, you start hacking. First of all, I’d like to share a few links: http://www.prideparrot.com/blog/archive/2012/5/exception_handling_in_asp_net_mvc http://benfoster.io/blog/aspnet-mvc-custom-error-pages http://www.secretge…

By on (tags: mvc, categories: code, web)

MVC parameter binding

Here’s a piece of information that will hopefully save you the time I spent on trying to figure it out… asp.net mvc parameter binding is localizable ONLY in the case of POST form action. So if you’re trying to bind a date time, and have globalization turned on in web.config, then you need to parse the parameter yourself. The parameter needs to be of type string, because making …

By on (tags: mvc, categories: code)

Because empty tags are bad

Well, not always, but there are times when they are so…what can I do to avoid them. Up to asp.net mvc 3 there’s a problem – if I want to render something wrapped in let’s say a paragraph, but I don’t want that paragraph to appear if the content is empty, then the markup looks like this: That’s a bit verbose. If I skip that check, then an empty hole is rendered on the page so ag…

By on (tags: mvc, categories: code)

MVC custom validator with client side validation

I wanted to have a reusable email validator since there have been a few cases already where I needed one. Previously I just used the RegularExpressionAttribute but that’s verbose for email. So, without thinking much, I created an attribute that derived from RegularExpressionAttribute and supplied it with a regex I used – that turned out to be a surprise. The server side validat…

By on (tags: mvc, categories: code)

MVC Greedy route mapping and custom route handler

I’m learning to love MVC mostly for it’s flexibility. In a recent situation, I wanted to have a generic controller that will perform CRUD (Create Read Update Delete) operations on an entity. By default, this is not handled, but with a little custom code, it turned out to be quite easy. Let me describe the use case first. The idea is to have a controller (let’s call it Foo) that…

By on (tags: mvc, categories: code)

Default route with areas in asp.net MVC

I stumbled upon a problem when trying to set up a default route for an asp.net mvc3 application. The routing mechanism itself is pretty straightforward, so I didn’t really expect any problems here, but as it turned out I was wrong. Here’s the stripped down version of the problem: Create a default mvc application – you’ll get the HomeController along with two actions there. Now …

By on (tags: area, mvc, route, categories: web)