Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

216
Views
Migration from .cshtml to *.razor

It's possible to use Url.Content and scripts in DummyPage.razor? It's necessary to implement the code from DummyPage.cshtml to DummyPage.razor.

@page "/apidocumentation"
<div class="container-flex">
    <div class="col-lg-12 control-section">
        <div class="content-wrapper">
            <div class="row">
                <rapi-doc spec-url="@Url.Content("doc/api/dummy.json")"></rapi-doc>

                <section Scripts>
                    <script src="@Url.Content("lib/rapidoc/dummy.js")"></script>
                </section>
                
            </div>
        </div>
    </div>
</div>

@code {

}

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

You need inject IJSRuntime for JS. It allows to load JavaScript code to your component.

If your JS function has a specific name, you can call with these function: InvokeAsync/InvokeVoidAsync.

Example:


Add script tag in your _Host.cshtml (P.S. ~ is equal to your wwwroot folder)

...
<script src="~/js/myJS.js"></script>
<script src="_framework/blazor.server.js"></script>

myJS.js

function MyScript(name) {
    return "Hello " + name;
}

Test.razor

@page "/test"
@inject IJSRuntime JS

<p id="myId">@Text</p>
<button @onclick="OnClick">Submit</button>

@code {
    private string Text { get; set; }

    private async void OnClick()
    {
        var exampleText = "World!";
        try
        {
            Text = await JS.InvokeAsync<string>("MyScript", exampleText);
        }
        catch(JSException ex)
        {
            Text = ex.Message;
        }

        StateHasChanged();
    }
}

Example after pushed the button: Example output with JS

If your JS script use a function onload (for example), you could override and use the OnAfterRenderAsync function.

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        //invoke only one time, after your component is loaded
        if (firstRender)
        {
            await JS.InvokeVoidAsync("onload");
        }
        
    }

I don't know rapi-doc, maybe you could pass the json through backend with a variable.

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!