Skip to content
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.

Razor Pages & Partial View Loading with Ajax #2073

Closed
fulviocanducci opened this issue Feb 15, 2018 · 2 comments
Closed

Razor Pages & Partial View Loading with Ajax #2073

fulviocanducci opened this issue Feb 15, 2018 · 2 comments
Labels

Comments

@fulviocanducci
Copy link

How to load Partial View with Ajax in Razor Pages?

@mkArtakMSFT
Copy link
Member

mkArtakMSFT commented Feb 15, 2018

Hi @fulviocanducci. Partial Views are aimed to create modular and reusable view sections to be rendered as part of the main view. While it's not intended to be used for the scenario you're describing, it is technically possible to expose an API on server side, which will return a PartialViewResult and then merge that result with the DOM from your JavaScript code.

PartialViewResult documentation: https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.partialviewresult?view=aspnetcore-2.0

@fulviocanducci
Copy link
Author

fulviocanducci commented Feb 15, 2018

@mkArtakMSFT

Good afternoon, I've read this documentation and really does not say anything about calling code snippets rendered with Ajax calls, for example:

namespace TesteAjaxPartialViews.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult About()
        {
            return View();
        }

        public ActionResult Contact()
        {
            return View();
        }

        public PartialViewResult DefinicaoArquitetura()
        {
            return PartialView();
        }
    }
}

<script type="text/javascript">

    function atualizarDefinicao() {
        $.ajax(
        {
            type: 'GET',
            url: '/Home/DefinicaoArquitetura',
            dataType: 'html',
            cache: false,
            async: true,
            success: function (data) {
                $('#definicaoArquitetura').html(data);
            }
        });
    }

    $(document).ready(function () {
        setInterval(atualizarDefinicao, 30000);
    });

</script>

Source: https://www.devmedia.com.br/asp-net-mvc-e-ajax-atualizando-o-conteudo-de-partial-views-via-jquery/26232

  • This was done in MVC would you like to know if you have how to do this with Razor Pages?
  • Is there a way to do this the way Razor Pages?
  • And why did you close the question?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants