Try passing the Student model to the partial view.
https://learn.microsoft.com/en-us/aspnet/core/mvc/views/partial?view=aspnetcore-7.0
@await Html.PartialAsync("_ViewStudent.cshtml", partialViewData)
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi. I want to include one in the project one partialview, however I do it, it doesn't work.
Here is example:
public class Student
{
public int Id { get; set; }
public string Name { get; set; }
}
public IActionResult ViewStudent()
{
Student std = new Student
{
Name = "John Doe",
Id = 1
};
return PartialView("_ViewStudent", std) }
<div>
<div class="container py-4">
@await Html.PartialAsync("_ViewStudent.cshtml")
</div>
</div>
@model Student;
<div>
<div>
<div> Student id: @Model.Id</div>
<div> Student id: @Model.Name</div>
</div>
</div>
When I run the application returns the following error:
System.NullReferenceException: 'Object reference not set to an instance of an object.'
Microsoft.AspNetCore.Mvc.Razor.RazorPage<TModel>.Model.get returned null.
Please help me to solve this issue.
Thank you!
Try passing the Student model to the partial view.
https://learn.microsoft.com/en-us/aspnet/core/mvc/views/partial?view=aspnetcore-7.0
@await Html.PartialAsync("_ViewStudent.cshtml", partialViewData)