{"id":10738,"date":"2014-05-12T08:00:11","date_gmt":"2014-05-12T12:00:11","guid":{"rendered":"http:\/\/blog.xamarin.com\/?p=10738"},"modified":"2014-05-12T08:00:11","modified_gmt":"2014-05-12T12:00:11","slug":"build-hybrid-apps-with-our-new-starter-kit","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/xamarin\/build-hybrid-apps-with-our-new-starter-kit\/","title":{"rendered":"Hybrid App Starter Kit"},"content":{"rendered":"<p>\t\t\t\tBuilding 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&#8217;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&#8217;t mean this should be your only option. But, you shouldn&#8217;t have to be saddled with an HTML-only framework in order to work with HTML.<\/p>\n<p>Wouldn&#8217;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#?<\/p>\n<h2>Behold! Portable Razor Starter Kit<\/h2>\n<p>You can use our new <a href=\"https:\/\/github.com\/xamarin\/PortableRazor\" title=\"PortableRazor project on GitHub\" target=\"_blank\">portable razor hybrid framework<\/a> to achieve just that. To help you get going, we&#8217;ve built a starter kit to show how to use PortableRazor to build a hybrid app targeting multiple platforms.<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/sites\/44\/2019\/04\/PortableCongress.png\" alt=\"Portable Congress\" width=\"405\" height=\"412\" class=\"aligncenter size-full wp-image-10750\" \/><\/p>\n<p>Our <a href=\"http:\/\/xamarin.com\/starter\" title=\"Xamarin Starter Edition\">starter-compatible<\/a> <a href=\"https:\/\/github.com\/xamarin\/PortableRazorStarterKit\" title=\"Portable Razor Starter Kit on GitHub\" target=\"_blank\">Portable Razor Starter Kit<\/a> shows how to use the portable razor framework to <a href=\"https:\/\/github.com\/xamarin\/PortableRazorStarterKit\" title=\"Portable Razor Starter Kit on GitHub\" target=\"_blank\">build a hybrid application<\/a> with Xamarin Studio. Using the Razor templating engine, it shows how to build a common core in C#, connected to a <a href=\"http:\/\/jquerymobile.com\/\" title=\"JQuery Mobile website\">JQuery Mobile<\/a> UI.<\/p>\n<p>If HTML, JavaScript, C# and Native APIs can get along, maybe Congress can too.<\/p>\n<p>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 &#8220;Portable Congress&#8221; &#8211; 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.<\/p>\n<p><a href=\"\/wp-content\/uploads\/sites\/44\/2019\/04\/PortableCongressSolution.png\"><img decoding=\"async\" src=\"\/wp-content\/uploads\/sites\/44\/2019\/04\/PortableCongressSolution-1024x598.png\" alt=\"Portable Congress Solution\" width=\"1024\" height=\"598\" class=\"aligncenter size-large wp-image-10753\" \/><\/a><\/p>\n<h2>Working with Portable Congress<\/h2>\n<p>Screens are added in Portable Congress by adding a new <strong>Preprocessed Razor Template<\/strong> (.cshtml) file in the Portable Congress <strong>Views<\/strong> folder. <\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/sites\/44\/2019\/04\/NewRazorTemplate.png\" alt=\"New RazorTemplate\" width=\"428\" height=\"326\" class=\"aligncenter size-full wp-image-10758\" \/><\/p>\n<p>This is the Razor template where you create your view. For example, the following code shows the template for the politician list screen:<\/p>\n<pre class=\"lang:html\">\n@inherits PortableRazor.ViewBase\n@model System.Collections.Generic.List&lt;Politician&gt;\n\n&lt;html&gt;\n&lt;head&gt;\n  &lt;link rel=&quot;stylesheet&quot; href=&quot;jquery.mobile-1.4.0.min.css&quot; \/&gt;\n  &lt;script src=&quot;jquery-1.10.2.min.js&quot;&gt;&lt;\/script&gt;\n  &lt;script src=&quot;jquery.mobile-1.4.0.min.js&quot;&gt;&lt;\/script&gt;\n  &lt;script src=&quot;jquery.lazyloadxt.js&quot;&gt;&lt;\/script&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n&lt;div data-role=&quot;header&quot; style=&quot;overflow:hidden;&quot; data-position=&quot;fixed&quot;&gt;\n  &lt;h1&gt;Congress&lt;\/h1&gt;\n&lt;\/div&gt;\n\n&lt;ul data-role=&quot;listview&quot; data-inset=&quot;true&quot; data-filter-placeholder=&quot;Search Congress...&quot; data-filter=&quot;true&quot;&gt;\n  @foreach(var p in Model) {\n  &lt;li&gt;\n    &lt;a href=&quot;@Url.Action(&quot;ShowPoliticianView&quot;, new {id = p.Id })&quot;&gt;\n      &lt;img src=&quot;loader.gif&quot; data-src=&quot;@Url.Content(p.ImageName)&quot;\/&gt;\n      &lt;h2&gt;@Html.Label(String.Format(&quot;{0} {1}&quot;, p.FirstName, p.LastName))&lt;\/h2&gt;\n      &lt;p&gt;@Html.Label(String.Format(&quot;{0} {1}&quot;, p.Party, p.State))&lt;\/p&gt;\n    &lt;\/a&gt;\n  &lt;\/li&gt;\n  }\n&lt;\/ul&gt;\n&lt;div data-role=&quot;footer&quot; data-id=&quot;foo1&quot; data-position=&quot;fixed&quot;&gt;\n  &lt;div data-role=&quot;navbar&quot;&gt;\n    &lt;ul&gt;\n      &lt;li&gt;&lt;a href=&quot;@Url.Action(&quot;ShowPoliticianList&quot;)&quot;&gt;Politicians&lt;\/a&gt;&lt;\/li&gt;\n      &lt;li&gt;&lt;a href=&quot;@Url.Action(&quot;ShowFavoriteBills&quot;)&quot;&gt;Bills&lt;\/a&gt;&lt;\/li&gt;\n    &lt;\/ul&gt;\n  &lt;\/div&gt;\n&lt;\/div&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/pre>\n<p>A view presents data from a model, which is implemented in C#. In the above example, the view presents a <strong>List&lt;Politician&gt;<\/strong> where <strong>Politician<\/strong> is a class implemented in C#. <\/p>\n<p>To call into C#, the view can leverage the <a href=\"http:\/\/www.asp.net\/mvc\" title=\"ASP.Net MVC\" target=\"_blank\">ASP.NET MVC<\/a> methods we&#8217;ve brought to Portable Razor, such as <strong>@Url.Action<\/strong> and <strong>@Html.ActionLink<\/strong>. For example, the following code uses <strong>@Url.Action<\/strong> to call the <strong>ShowPoliticianView<\/strong> method:<\/p>\n<pre class=\"lang:html\">\n&lt;a href=&quot;@Url.Action(&quot;ShowPoliticianView&quot;, new {id = p.Id })&quot;&gt;\n<\/pre>\n<p><strong>ShowPoliticianView<\/strong> is implemented in the controller to query and present the data in the view generated by Razor:<\/p>\n<pre class=\"lang:csharp decode:true\">\npublic Politician ShowPoliticianView(int id) {\n  var politician = dataAccess.LoadPolitician (id);\n\n  var template = new PoliticianView { Model = politician };\n  var page = template.GenerateString ();\n\n  webView.LoadHtmlString (page);\n  return politician;\n}\n<\/pre>\n<p>With <strong><a href=\"https:\/\/github.com\/xamarin\/PortableRazor\" title=\"PortableRazor project on GitHub\" target=\"_blank\">Portable Razor<\/a><\/strong> and <strong><a href=\"https:\/\/github.com\/xamarin\/PortableRazorStarterKit\" title=\"Portable Razor Starter Kit\" target=\"_blank\">Portable Congress<\/a><\/strong>, 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 <a href=\"\/sharper-html-hybrid-apps-with-razor\/\" title=\"Getting started with Razor templates\" target=\"_blank\">getting started  with Razor templates post<\/a>.<\/p>\n<p><a href=\"https:\/\/forums.xamarin.com\/16583\/\" title=\"Hybrid App Starter Kit\"><em>Discuss this post in the Xamarin forums.<\/em><\/a>\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;s useful to blend some HTML into your native app, for instance to reuse some existing HTML assets. While in most cases, using [&hellip;]<\/p>\n","protected":false},"author":546,"featured_media":39167,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[4],"class_list":["post-10738","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-developers","tag-xamarin-platform"],"acf":[],"blog_post_summary":"<p>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&#8217;s useful to blend some HTML into your native app, for instance to reuse some existing HTML assets. While in most cases, using [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts\/10738","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/users\/546"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/comments?post=10738"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts\/10738\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/media\/39167"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/media?parent=10738"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/categories?post=10738"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/tags?post=10738"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}