Skip to main content
Home  › ... Razor

WebApi Tutorials

Tutorial Home

Learn how to create and use WebApi to provide data to JavaScript SPA apps.

Some notes before we start

WebApi is not directly razor, as it's not meant to actualy render HTML. It's coded using C# just like razor, but won't have commands like @Html.Raw(...). Since it's the best way to communicate from the server with your JavaScript apps, we've included the basics in this tutorial.

Our examples use very trivial JavaScript code to call the API and show the results. Your SPA apps will usually be more sophisticated, but that would then be a topic for a JavaScript tutorial.

Source Code of this file

Below you'll see the source code of the file. Note that we're just showing the main part, and hiding some parts of the file which are not relevant for understanding the essentials. Click to expand the code

@inherits Custom.Hybrid.Razor14
<!-- unimportant stuff, hidden -->

<div @Sys.PageParts.InfoWrapper()>
  @Html.Partial("../shared/_DefaultInfoSection.cshtml")
  <div @Sys.PageParts.InfoIntro()>
      <p>
        Learn how to create and use <strong>WebApi</strong> to provide data to JavaScript SPA apps. 
      </p>

      <h2>Some notes before we start</h2>
      <p>
        WebApi is not directly razor, as it's not meant to actualy render HTML. It's coded using C# just like razor, 
        but won't have commands like <code>@@Html.Raw(...)</code>. Since it's the best way to communicate from the server with your JavaScript apps, we've included the basics in this tutorial. 
      </p>
      <p>
        Our examples use very trivial JavaScript code to call the API and show the results. Your SPA apps will usually be more sophisticated, but that would then be a topic for a JavaScript tutorial. 
      </p>
    </div>
  </div>