9 Aug 2012

Visual Studio RegEx for converting old MVC Views to Razor format

This won't fix everything, but does help a lot with converting your old MVC Views to Razor format.

Basically this is RegEx replacement pattern for use in the Visual Studio Find and Replace dialog, for converting out all the old <%: blah %> tags.

Find what:

\<%\::b*{.#}:b*%\>

Replace with:

@\1

Don't forget to Use Regular Expressions in the Find Options.

Some of the resultant code won't work until you put brackets round it e.g. @blah blah needs to be @(blah blah)

Don't forget you may need to convert <%= blah %> tags too - perhaps convert them to @Html.Raw(blah)

Don't forget you may need to convert <% blah %> tags too - perhaps convert them to @{blah}

No comments:

Post a Comment

Comments are very welcome but are moderated to prevent spam.

If I helped you out today, you can buy me a beer below. Cheers!