By default code blocks are not allowed on Master pages or Page layouts.
You have to allow them in web.config using the following code:
<pageparserpaths>
<pageparserpath virtualpath="/_catalogs/masterpage/*" compilationmode="Always" allowserversidescript="true" includesubfolders="true".>
</pageparserpaths>