|
| 1 | +--- |
| 2 | +title: Getting Started |
| 3 | +page_title: Getting Started |
| 4 | +description: "Make your first steps with the Telerik UI for {{ site.framework }} QRCode component by following a complete step-by-step tutorial." |
| 5 | +slug: qrcode_getting_started |
| 6 | +position: 1 |
| 7 | +--- |
| 8 | + |
| 9 | +# Getting Started with the QRCode |
| 10 | + |
| 11 | +This tutorial explains how to set up a basic Telerik UI for {{ site.framework }} QRCode and highlights the major steps in the configuration of the component. |
| 12 | + |
| 13 | +You will initialize a QRCode component that will display a [Card](https://demos.telerik.com/aspnet-core/cards) with a vacation offer when the QR code is scanned. Next, you will dynamically update the QRCode value through a single button click. {% if site.core %}Finally, you can run the sample code in [Telerik REPL](https://netcorerepl.telerik.com/) and continue exploring the components.{% endif %} |
| 14 | + |
| 15 | +  |
| 16 | + |
| 17 | +@[template](/_contentTemplates/core/getting-started-prerequisites.md#component-gs-prerequisites) |
| 18 | + |
| 19 | +## 1. Prepare the CSHTML File |
| 20 | + |
| 21 | +@[template](/_contentTemplates/core/getting-started-directives.md#gs-adding-directives) |
| 22 | + |
| 23 | +Optionally, you can structure the View content by adding the desired HTML elements like headings, divs, paragraphs, and others. |
| 24 | + |
| 25 | +```HtmlHelper |
| 26 | + @using Kendo.Mvc.UI |
| 27 | + <div id="qr-wrap" style="text-align: center;"> |
| 28 | + <h4>Scan the QR code to review a vacation offer.</h4> |
| 29 | + </div> |
| 30 | +``` |
| 31 | +{% if site.core %} |
| 32 | +```TagHelper |
| 33 | + @addTagHelper *, Kendo.Mvc |
| 34 | + <div id="qr-wrap" style="text-align: center;"> |
| 35 | + <h4>Scan the QR code to review a vacation offer.</h4> |
| 36 | + </div> |
| 37 | +``` |
| 38 | +{% endif %} |
| 39 | + |
| 40 | +## 2. Initialize the QRCode |
| 41 | + |
| 42 | +Use the QRCode HtmlHelper {% if site.core %}or TagHelper{% endif %} to add the component to a page: |
| 43 | + |
| 44 | +* The `Name()` configuration method is mandatory as its value is used for the `id` and the `name` attributes of the QRCode element. |
| 45 | +* The `Value()` options specifies the QRCode value. |
| 46 | +* Customize the component appearance by using the `Size()`, `Color()`, and `Border()` methods. |
| 47 | + |
| 48 | +```HtmlHelper |
| 49 | + @using Kendo.Mvc.UI |
| 50 | +
|
| 51 | + @(Html.Kendo().QRCode() |
| 52 | + .Name("vacationQrCode") |
| 53 | + .Value("https://demos.telerik.com/kendo-ui/qrcode/index") |
| 54 | + .Size(170) |
| 55 | + .Color("#000000") |
| 56 | + .Border(border => border.Color("#000000").Width(5)) |
| 57 | + ) |
| 58 | +``` |
| 59 | +{% if site.core %} |
| 60 | +```TagHelper |
| 61 | + @addTagHelper *, Kendo.Mvc |
| 62 | +
|
| 63 | + <kendo-qrcode name="vacationQrCode" |
| 64 | + value="https://demos.telerik.com/kendo-ui/qrcode/index" |
| 65 | + size="170" |
| 66 | + color="#000000"> |
| 67 | + <border color="#000000" width="5" /> |
| 68 | + </kendo-qrcode> |
| 69 | +``` |
| 70 | +{% endif %} |
| 71 | + |
| 72 | +## 3. Configure the Card |
| 73 | + |
| 74 | +The next step is to define the Card component with the vacation information that will be displayed when you scan the QR code. |
| 75 | + |
| 76 | +```HTML |
| 77 | + <div class="card-container"> |
| 78 | + <div class="k-card k-card-vertical"> |
| 79 | + <img class="k-card-image" alt="Telerik UI for ASP.NET Core Cards Africa" src="https://demos.telerik.com/aspnet-core/shared/web/cards/south-africa.jpg"/> |
| 80 | + <div class="k-card-body"> |
| 81 | + <h5 class="k-card-title">African Safari</h5> |
| 82 | + <p>Africa provides some of the most epic wildlife diversity on the planet. Not many vacations involve sleeping in close quarters with lions, leopards, elephants, buffaloes, rhinos, giraffes and hippos.</p> |
| 83 | + </div> |
| 84 | + <div class="k-card-actions k-card-actions-vertical k-card-actions-stretched"> |
| 85 | + <span class="k-button k-button-flat-primary k-button-flat k-button-md k-rounded-md">Book now</span> |
| 86 | + <span class="k-button k-button-flat-primary k-button-flat k-button-md k-rounded-md">Check rates</span> |
| 87 | + </div> |
| 88 | + </div> |
| 89 | + </div> |
| 90 | +``` |
| 91 | + |
| 92 | +Add the Card declaration in a Telerik REPL sample and insert its URL in the QRCode `Value()` method. |
| 93 | + |
| 94 | +```HtmlHelper |
| 95 | + @using Kendo.Mvc.UI |
| 96 | +
|
| 97 | + @(Html.Kendo().QRCode() |
| 98 | + .Name("vacationQrCode") |
| 99 | + .Value("https://netcorerepl.telerik.com/mnbmQncO07oE3ier03") |
| 100 | + ... // Other configuration. |
| 101 | + ) |
| 102 | +``` |
| 103 | +{% if site.core %} |
| 104 | +```TagHelper |
| 105 | + @addTagHelper *, Kendo.Mvc |
| 106 | +
|
| 107 | + <kendo-qrcode name="vacationQrCode" value="https://netcorerepl.telerik.com/mnbmQncO07oE3ier03"> |
| 108 | + <!-- Other configuration --> |
| 109 | + </kendo-qrcode> |
| 110 | +``` |
| 111 | +{% endif %} |
| 112 | + |
| 113 | +## 4. (Optional) Reference Existing QRCode Instances |
| 114 | + |
| 115 | +You can reference the QRCode instances that you have created and build on top of their existing configuration: |
| 116 | + |
| 117 | +1. Use the `id` attribute of the component instance to get its reference. |
| 118 | + |
| 119 | + ```script |
| 120 | + <script> |
| 121 | + $(document).ready(function() { |
| 122 | + var qrCodeReference = $("#vacationQrCode").data("kendoQRCode"); // qrCodeReference is a reference to the existing QRCode instance of the helper. |
| 123 | + }); |
| 124 | + </script> |
| 125 | + ``` |
| 126 | +
|
| 127 | +1. Use the [QRCode client-side API](https://docs.telerik.com/kendo-ui/api/javascript/dataviz/ui/qrcode#methods) to control the behavior of the component. In this example, you will use the `value()` method to dynamically change the value of the QRCode (for example, when a button is clicked). |
| 128 | +
|
| 129 | + ```HtmlHelper |
| 130 | + @(Html.Kendo().Button() |
| 131 | + .Name("updateQRCodeBtn") |
| 132 | + .Content("Update QRCode") |
| 133 | + .Events(ev => ev.Click("onBtnClick")) |
| 134 | + ) |
| 135 | + ``` |
| 136 | + {% if site.core %} |
| 137 | + ```TagHelper |
| 138 | + @addTagHelper *, Kendo.Mvc |
| 139 | + <kendo-button name="updateQRCodeBtn" on-click="onBtnClick"> |
| 140 | + Update QRCode |
| 141 | + </kendo-button> |
| 142 | + ``` |
| 143 | + {% endif %} |
| 144 | + ```Scripts |
| 145 | + <script> |
| 146 | + function onBtnClick() { |
| 147 | + var qrCodeReference = $("#vacationQrCode").data("kendoQRCode"); |
| 148 | + qrCodeReference.value("mailto:[email protected]"); |
| 149 | + } |
| 150 | + </script> |
| 151 | + ``` |
| 152 | +
|
| 153 | +For more information on referencing specific helper instances, see the [Methods and Events]({% slug methodevents_core %}) article. |
| 154 | +
|
| 155 | +{% if site.core %} |
| 156 | +## Explore this Tutorial in REPL |
| 157 | +
|
| 158 | +You can continue experimenting with the code sample above by running it in the Telerik REPL server playground: |
| 159 | +
|
| 160 | +* [Sample code with the QRCode HtmlHelper](https://netcorerepl.telerik.com/QxFmwxwu22AIHKrN25) |
| 161 | +* [Sample code with the QRCode TagHelper](https://netcorerepl.telerik.com/QnlQcdQa25Fddbrd25) |
| 162 | +
|
| 163 | +{% endif %} |
| 164 | +
|
| 165 | +## Next Steps |
| 166 | +
|
| 167 | +* [QRCode Encodings]({% slug encoding_qrcode_aspnetcore_helper %}) |
| 168 | +* [Setting the overlay of the QRCode]({% slug types_qrcodehelper_aspnetcore %}) |
| 169 | +
|
| 170 | +## See Also |
| 171 | +
|
| 172 | +* [Using the API of the QRCode for {{ site.framework }} (Demo)](https://demos.telerik.com/{{ site.platform }}/qrcode/api) |
| 173 | +* [Client-Side API of the QRCode](https://docs.telerik.com/kendo-ui/api/javascript/dataviz/ui/qrcode) |
| 174 | +* [Server-Side API of the QRCode](/api/qrcode) |
| 175 | +{% if site.core %} |
| 176 | +* [Server-Side API of the QRCode TagHelper](/api/taghelpers/qrcode) |
| 177 | +{% endif %} |
| 178 | +* [Knowledge Base Section](/knowledge-base) |
0 commit comments