Building native apps with Xamarin is the best of both worlds. You get the best possible experience on each platform, while being able to reuse vast amounts of code everywhere. Sometimes though, it’s useful to blend some HTML into your native app, for instance to reuse some existing HTML assets. While in most cases, using native APIs achieves a far better experience, that doesn’t mean this should be your only option. But, you shouldn’t have to be saddled with an HTML-only framework in order to work with HTML.

Wouldn’t it be great to have an easy way to use HTML in your mobile apps but keep the core of the application in C#?

Behold! Portable Razor Starter Kit

You can use our new portable razor hybrid framework to achieve just that. To help you get going, we’ve built a starter kit to show how to use PortableRazor to build a hybrid app targeting multiple platforms.

Portable Congress

Our starter-compatible Portable Razor Starter Kit shows how to use the portable razor framework to build a hybrid application with Xamarin Studio. Using the Razor templating engine, it shows how to build a common core in C#, connected to a JQuery Mobile UI.

If HTML, JavaScript, C# and Native APIs can get along, maybe Congress can too.

The sample kit includes the Portable Congress application, which is a data-driven mobile application that provides easy access to members of the United States Congress. Portable Congress is implemented in a core PCL project named “Portable Congress” – clever! Here you will find the cross-platform views, controllers and web service code. Additionally, platform projects are provided to bootstrap the native portions of the application on both Android and iOS.

Portable Congress Solution

Working with Portable Congress

Screens are added in Portable Congress by adding a new Preprocessed Razor Template (.cshtml) file in the Portable Congress Views folder.

New RazorTemplate

This is the Razor template where you create your view. For example, the following code shows the template for the politician list screen:

A view presents data from a model, which is implemented in C#. In the above example, the view presents a List<Politician> where Politician is a class implemented in C#.

To call into C#, the view can leverage the ASP.NET MVC methods we’ve brought to Portable Razor, such as @Url.Action and @Html.ActionLink. For example, the following code uses @Url.Action to call the ShowPoliticianView method:

ShowPoliticianView is implemented in the controller to query and present the data in the view generated by Razor:

With Portable Razor and Portable Congress, you now have a great starting point for building hybrid applications with Xamarin. To learn more on how to create hybrid apps with Razor templates from scratch, be sure to read our getting started with Razor templates post.

Discuss this post in the Xamarin forums.