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

374
Views
El envío de valores de Javascript a Blazor no funciona (enlace de dos datos)

En mi script Java, envío el Lan/Long de mi mapa a blazor. Puedo ver los cambios de longitud y latitud en el navegador, pero quiero pasarlos a mi método blazor para realizar algún procesamiento. los valores devueltos siempre 0.

Aquí está mi método have script:

 function GetCircle(e){ r = document.getElementById("InputRadius").value; if (circle !== null) { map.removeLayer(circle); } circle = new L.circle([ Lat,Long],{radius:r}); map.addLayer(circle); circle.bindPopup( "<br/> Radius is : " + r +" Meter" ).openPopup(); document.getElementById("Lat").value = Lat; //send this to blazor document.getElementById("Long").value = Long; // send this to blazor }

Como puede ver en el código anterior, cuando el usuario hace clic en el mapa, obtengo la longitud/latitud y luego los envío a blazor.

Mi página de afeitar: tengo las siguientes entradas que estoy usando para almacenar los datos dentro de ellas y luego pasar los datos al método blazor en la sección 'código'

 <input type="text" @bind="Lat" id="Lat" name="Lat" > <input type="text" @bind="Long" id="Long" name = "Long" > @code { int InputRadius; double Long; double Lat; string date_selected; string time_selected; public async Task GetTgas() { AllTags = await Task.Run(() => tagsService.Map( InputRadius, Long,Lat,date_selected,time_selected)); } public async Task GetCircle() { await JSRuntime.InvokeVoidAsync("GetCircle"); } }

Puedo ver el Lan/Long en mi vista perfectamente cuando hago clic en GetCircle, lo que significa que pasaron de JS a la página blazor con éxito, pero al hacer la función GetTags no pasan a mi método blazor.

¡Cualquier ayuda será bien recibida!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Su método GetCircle debería ser así, necesita enviar una referencia de objeto .net a la función javascript

 await JS.InvokeVoidAsync("GetCircle", DotNetObjectReference.Create(this));

Y su función GetTags debería ser así, debería poder invocarse desde javascript

 [JSInvokable] public async Task GetTags(double lati, double longi) { AllTags = await Task.Run(() => tagsService.Map(InputRadius, longi,lati,date_selected,time_selected)); }

Su función javascript debería ser así

 function GetCircle(dotNetHelper){ r = document.getElementById("InputRadius").value; if (circle !== null) { map.removeLayer(circle); } circle = new L.circle([ Lat,Long],{radius:r}); map.addLayer(circle); circle.bindPopup( "<br/> Radius is : " + r +" Meter" ).openPopup(); // send this to blazor dotNetHelper.invokeMethodAsync('GetTags', Lat, Long); }
about 4 years ago · Juan Pablo Isaza 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!