Top Page level View is named "Create.cshtml"
On that page I need to place multiple _partialViews.cshtml which I have made using razor pages:
<div>
<row>
<div class="col-md-6">
@await Html.PartialAsync("~/Views/Shared/_PartialDelegates")
</div>
<div class="col-md-6">
@await Html.PartialAsync("~/Views/Shared/_PartialApps")
</div>
</row>
</div>
Now the problem is I am trying to call _PartialDelegates.cshtml w/ _PartialDelegates.cs
_PartialDelegates.cshtml
@page
@model IMP.ECR.WEB.Views.Shared._PartialDelegatesModel
@{
}
<partial name="_PartialDelegatesView" model="Model.Avengers" />
Which calls _PartialDelegates.cshtml.cs
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace IMP.ECR.WEB.Views.Shared
{
public class _PartialDelegatesModel : PageModel
{
public List<string> Avengers = new List<string>();
public void OnGet()
{
Avengers.AddRange(new[] { "Spiderman", "Iron Man", "Dr. Stange", "The Hulk" });
}
}
}
}
Then in _PartialDelegatesView.cshtml I have the following:
@model List<string>
<div class="col-md-12">
<h2>Avengers</h2>
<table class="table table-boardered table-striped" style="width:100%">
@foreach (var item in Model)
{
<tr>
<td>@item</td>
</tr>
}
</table>
</div>
But, I keep getting an unhandled exception ---
An unhandled exception occurred while processing the request.
NullReferenceException: Object reference not set to an instance of an
object.
AspNetCore.Views_Shared__PartialDelegates.get_Model()
NullReferenceException: Object reference not set to an instance of an object.
AspNetCore.Views_Shared__PartialDelegates.get_Model()
AspNetCore.Views_Shared__PartialDelegates.ExecuteAsync() in _PartialDelegates.cshtml
+
<partial name="_PartialDelegatesView" model="Model.Avengers" />
Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context)
Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, bool invokeViewStarts)
Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)
Microsoft.AspNetCore.Mvc.ViewFeatures.HtmlHelper.RenderPartialCoreAsync(string partialViewName, object model, ViewDataDictionary viewData, TextWriter writer)
Microsoft.AspNetCore.Mvc.ViewFeatures.HtmlHelper.PartialAsync(string partialViewName, object model, ViewDataDictionary viewData)
AspNetCore.Views_Sponsors_Create.ExecuteAsync() in Create.cshtml
+
@await Html.PartialAsync("~/Views/Shared/_PartialDelegates.cshtml")
Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context)
Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, bool invokeViewStarts)
Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, string contentType, Nullable<int> statusCode)
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ActionContext actionContext, IView view, ViewDataDictionary viewData, ITempDataDictionary tempData, string contentType, Nullable<int> statusCode)
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext context, ViewResult result)
Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext context)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultAsync(IActionResult result)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResultFilterAsync<TFilter, TFilterAsync>()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResultExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.ResultNext<TFilter, TFilterAsync>(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultFilters()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)