Description
While updating to .NET Core 2.1, I replaced my @Html.Partial
loads to the new partial tag helper as recommended by the compiler warnings.
In two cases, I could rely on the for
syntax, rather than using the model
attribute:
The
for
attribute assigns a ModelExpression to be evaluated against the current model. AModelExpression
infers the@Model
. syntax. For example,for="Product"
can be used instead offor="@Model.Product"
.
At first, I had the impression this worked as my partials showed up correctly. However, I just found out my partial reloads stopped working due the the model not being transferred to my controllers correctly; something which worked just fine before.
I use the following javascript to intercept a form submission and send/handle a post request:
$(addForm).on("submit", function (e) {
e.preventDefault();
// Do not submit if form is invalid.
if (!$(this).valid()) {
return false;
}
$.ajax({
url: $(this).attr("action"),
type: "POST",
data: $(this).serialize(),
complete: function () {
...
}
}).done(function (result) {
partialView.html(result);
...
});
});
When I change my partials to use the model
attribute instead, things work fine again: <partial name="Details/_CommentsPartial" model="@Model.Comments" />
.
This seems like a bug to me? Possibly relevant, this is a nested partial (partial in partial).