Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Blazor with ASP.NET Core MVC project

$
0
0

I have an ASP.NET Core MVC project where I'm trying to add Blazor specially because we have a lot of dynamic forms inside modals, and is a pain in the ... handle all in javascript + modelstate and such....

My first attempt at adding Blazor! I tried the simplest example with a counter, and I add the component into our index.cshtml and everything works fine.

Index.cshtml

<component type="typeof(myapp.MyComponent)" render-mode="ServerPrerendered" />

Again the counter works fine.

In another page called OurSpec.cshtml, I have a modal:

<div class="modal fade" data-bs-backdrop="static" id="modal-client" tabindex="-1" role="dialog" aria-hidden="true"><div class="modal-dialog modal-dialog-centered modal-xl" role="document"><div class="modal-content position-relative"><div class="modal-header"><h5 class="modal-title" id="exampleModalCenterLabel">                    Client </h5><button type="button" id="btn-close-modal" class="btn-close btn btn-sm btn-circle d-flex flex-center transition-base" data-bs-dismiss="modal" aria-label="Close"></button></div><div class="modal-body p-0"><component type="typeof(myapp.MyComponent)" render-mode="ServerPrerendered" /></div><div class="modal-footer"><button class="btn btn-secondary" type="button" data-bs-dismiss="modal">Voltar</button><button class="btn btn-primary" type="submit" id="btnSave">Salvar</button></div></div></div></div>

This modal is a partial view that is called via AJAX, the counter show 0 ok but the button counterUp does not work, the method UpdateCount is not even been triggered - I have no idea why.... Can anyone help?

This is the code in MyComponent:

<h3>Classic Blazor</h3><span> counter: @contador</span><button @onclick="@UpdateCount">up count</button>@code {    int contador = 0;    public void UpdateCount()    {        contador++;    }}

I have tried a lot of suggestions in gpt, internet but nothing works I'm using ASP.NET Core 8 btw


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>