Home Net Core Inline Razor Markup Null Model
Reply: 0

Net Core Inline Razor Markup Null Model

user1248 Published in May 26, 2018, 9:41 pm

My first go with Razor Pages inline markup. Running into this weird issue after passing a ViewModel to a PartialView.

Of course in my parent page I pass the ViewModel to the PartialView:

@{Html.RenderPartial("Partial/_RequestView", Model.NewRequest);}

public class IndexModel : PageModel
    private readonly IActiveDirectoryClient _activeDirectoryClient;
    private readonly ITravelClient _travelClient;
    public IEnumerable<TravelRequestViewModel> Requests { get; set; }

In the partial view, I have no issue referencing the model in a lambda expression

@Html.HiddenFor(model => model.RequestId)

However when I attempt to reference the Model in razor markup inline the Model is null. Any ideas?


The NewRequest property is set within the OnGetAsync() method in the parent page

    public async Task<IActionResult> OnGetAsync()
        NewRequest = BuildNewRequest();
        if (NewRequest == null)
            throw new NullReferenceException("Unable to build new travel request");

        return await Task.FromResult(Page());
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.305887 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO