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

221
Views
Migración de .cshtml a *.razor

¿Es posible usar Url.Content y scripts en DummyPage.razor? Es necesario implementar el código de DummyPage.cshtml a 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

Necesita inyectar IJSRuntime para JS. Permite cargar código JavaScript a su componente.

Si su función JS tiene un nombre específico, puede llamar con esta función: InvokeAsync/InvokeVoidAsync .

Ejemplo:


Agregue una etiqueta de secuencia de comandos en su _Host.cshtml (PS ~ es igual a su carpeta wwwroot )

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

miJS.js

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

Prueba.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(); } }

Ejemplo después de pulsar el botón: Ejemplo de salida con JS

Si su secuencia de comandos JS usa una función de onload (por ejemplo), puede anular y usar la función OnAfterRenderAsync.

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

No sé rapi-doc, tal vez podrías pasar el json a través del backend con una 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!