Tag: ASP.NET Core

  • Rendering output using Razor

    Rendering output using Razor

    When rendering output from a razor template it is important to remember the distinction between

    @{ ...}  and @(...)

    Curly braces will cause the output to execute, whilst the regular parenthesis will cause the output to render.

    As an example that tripped me up during rendering of a ViewComponent in the CamperFinder demo, the following executes the output, but does not render it.

    <div>     
    @foreach (var vehicle in Model.Vehicles) {
      @await Component.InvokeAsync("VehicleSummary", vehicle);
    }
    </div>@

    The inner await block is executed within the scope of the loop, within {} braces.

    By adding parentheses around the await following renders the content as we want it.

    <div>     
    @foreach (var vehicle in Model.Vehicles) {
      @(await Component.InvokeAsync("VehicleSummary", vehicle));
    }
    </div>

    Kudos: https://stackoverflow.com/a/44835742/75594

  • Azure: deploy multiple websites from a single solution

    Azure: deploy multiple websites from a single solution

    A typically used scenario is to have a solution with two or more web apps. This might be a website project followed by one or more Web API projects.

    1. Create a Resource Group.
    2. Add a Web App for each website being deployed.
    3. For each web app –
      1. Within Application Settings for each web-app add a new setting:
        1. Name: PROJECT
        2. Value: [foldername]/[projectname].csproj
      2. Configure a deployment strategy, for example; using Github

    When you commit your code (or your chosen deployment strategy is triggered) all the Azure web apps will deploy their respective projects.