How to update a Partial View through a Post?

Asked

Viewed 76 times

0

I am using Asp.Net Core Razor pages and need to avoid using Javascript/Ajax/Blazor in my code to create something like a control iterative, adding to the page a form at each button click and trying to do this through two partial Views:

[Page code ...]    
@{
    await Html.RenderPartialAsync("Shared/_PrimeiraPartial", new Shared._PrimeiraPartialModel(), ViewData);
}
[...]

Partialmodel

 public class _PrimeiraPartialModel: PageModel
{
    public void OnGet()
    {

    }

    public PartialViewResult OnPostMyPartial()
    {
        var part = new PartialViewResult()
        {
            ViewName = "Shared/_SegundaPartial"
        };


        return part;
    }
}

Primeira Partialhtml

@page "{handler?}"
@model LojaVirtual.Pages.Product.Shared._ImageUploadModel

<a asp-page-handler="OnPostMyPartial" asp-page="_PrimeiraPartial" class="btn btn-danger m-3">UpdatePartial</a>

The problem is when the method Onpostmypartial runs it not only updates the first Partialview with the content of the second but the main page

  • If you are not going to use Javascript, Ajax or Blazor... it makes no sense at all the partial views, because every post you will have to render the entire screen as a single view...

  • Thank you for your reply. I understand, my problem is that when updating the view, it updates itself whole as the second partial view, I wonder if there is only how to update the part belonging to the first Partialview

  • Only with Javascript and Ajax, or will have to take and bring all the data from the other views

  • I understand, thank you.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.