How to use ViewDataDictionary with Html.Partial in asp.net core? : <p>My case looks like this:</p>

<p>Model:</p>

<pre><code>public class Book
{
    public string Id { get; set; }

    public string Name { get; set; }
}

public class Comment
{
    public string Id { get; set; }

    public string BookId { get; set; }

    public string Content { get; set; }    
}
</code></pre>

<p>Controller:</p>

<pre><code>public IActionResult Detail(string id)
{
    ViewData["DbContext"] = _context; // DbContext

    var model = ... // book model

    return View(model);
}
</code></pre>

<p>View:</p>

<p>Detail view:</p>

<pre><code>@if (Model?.Count &gt; 0)
{
    var context = (ApplicationDbContext)ViewData["DbContext"];
    IEnumerable&lt;Comment&gt; comments = context.Comments.Where(x =&gt; x.BookId == Model.Id);

    @Html.Partial("_Comment", comments)
}
</code></pre>

<p>Comment partial view:</p>

<pre><code>@model IEnumerable&lt;Comment&gt;

@if (Model?.Count &gt; 0)
{
    &lt;!-- display comments here... --&gt;
}

&lt;-- How to get "BookId" here if Model is null? --&gt;
</code></pre>

<p>I've tried this:</p>

<pre><code>@Html.Partial("_Comment", comments, new ViewDataDictionary { { "BookId", Model.Id } })
</code></pre>

<p>Then</p>

<pre><code>@{
    string bookid = ViewData["BookId"]?.ToString() ?? "";
}

@if (Model?.Count() &gt; 0)
{
    &lt;!-- display comments here... --&gt;
}

&lt;div id="@bookid"&gt;
    other implements...
&lt;/div&gt;
</code></pre>

<p>But error:</p>

<blockquote>
  <p>'ViewDataDictionary' does not contain a constructor that takes 0
  arguments</p>
</blockquote>

<p>When I select <code>ViewDataDictionary</code> and press <code>F12</code>, it hits to:</p>

<pre><code>namespace Microsoft.AspNetCore.Mvc.ViewFeatures
{
    public ViewDataDictionary(IModelMetadataProvider metadataProvider, ModelStateDictionary modelState);
}
</code></pre>

<p>I don't know what are <code>IModelMetadataProvider</code> and <code>ModelStateDictionary</code>?</p>

<p>My goal: Send model <code>comments</code> from view <code>Detail.cshtml</code> to partial view <code>_Comment.cshtml</code> with a <code>ViewDataDictionary</code> which contains <code>BookId</code>.</p>

<p>My question: How can I do that?</p>
