In my code I have @Html.Partial("_StatusMessage", Model.StatusMessage)
but Visual Studio warning me that: Error MVC1000: Use of IHtmlHelper.Partial may result in application deadlocks. Consider using <partial> Tag Helper or IHtmlHelper.PartialAsync.
Should I disable this error or I should really change @Html.Partial
to @Html.PartialAsync
, and why?
The primary difference between the two methods is that Partial generates the HTML from the View and returns it to the View to be incorporated into the page. RenderPartial, on the other hand, doesn't return anything and, instead, adds its HTML directly to the Response object's output.
Returns HTML markup for the specified partial view. PartialAsync(IHtmlHelper, String, ViewDataDictionary) Returns HTML markup for the specified partial view.
Partial views are an effective way to: Break up large markup files into smaller components. In a large, complex markup file composed of several logical pieces, there's an advantage to working with each piece isolated into a partial view.
Creating Partial View To create a partial view, right-click on view -> shared folder and select Add -> View option. In this way we can add a partial view.
Yes we should, See below section from their official site
Migrate from an HTML Helper
Consider the following asynchronous HTML Helper example. A collection of products is iterated and displayed. Per the PartialAsync method's first parameter, the _ProductPartial.cshtml partial view is loaded. An instance of the Product model is passed to the partial view for binding.
CSHTML @foreach (var product in Model.Products) { @await Html.PartialAsync("_ProductPartial", product) }
The following Partial Tag Helper achieves the same asynchronous rendering behavior as the PartialAsync HTML Helper. The model attribute is assigned a Product model instance for binding to the partial view.
CSHTML @foreach (var product in Model.Products) { <partial name="_ProductPartial" model="product" /> }
Copied from https://docs.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/built-in/partial-tag-helper?view=aspnetcore-2.1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With