最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Having trouble using fetch API to load ASP.NET MVC partial view which includes Quill rich-text editors - Stack Over

programmeradmin2浏览0评论

I am trying to use fetch to load a partial view which includes several Quill containers. Using Fetch, the Quill editors are not rendered. There is no comparable problem using jQuery's load method.

The Fetch call looks something like the following, found with Google:

async function loadPartialView(url, container) {
    await fetch(url)
        .then(response => response.text())
        .then(html => {
            document.getElementById(container).innerHTML = html;
        })
        .catch(error => {
            console.error('Error fetching PartialView:', error);
        });
}

The code for the Quill editors is loaded from the partial view.

I am trying to use fetch to load a partial view which includes several Quill containers. Using Fetch, the Quill editors are not rendered. There is no comparable problem using jQuery's load method.

The Fetch call looks something like the following, found with Google:

async function loadPartialView(url, container) {
    await fetch(url)
        .then(response => response.text())
        .then(html => {
            document.getElementById(container).innerHTML = html;
        })
        .catch(error => {
            console.error('Error fetching PartialView:', error);
        });
}

The code for the Quill editors is loaded from the partial view.

Share Improve this question edited Mar 19 at 20:51 President James K. Polk 42.1k29 gold badges109 silver badges145 bronze badges asked Mar 17 at 15:34 MomeneeMomenee 337 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

You need to initialize the Quill containers in the fetch method after the PartialView is loaded into the DOM. With jQuery.load, I had been initializing Quill in the PartialView.

Google's AI Overview gave me the answer:

fetch('/your-partial-view-url')
      .then(response => response.text())
      .then(html => {
        document.getElementById('your-container').innerHTML = html;
        initializeQuill();
      })
      .catch(error => console.error('Error fetching partial view:', error));

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论