Reputation:
I have a partial view called _Subscribe.cshtml
Is it okay for partial views to have a page model _Subscribe.cshtml.cs?
I want to allow people who visit my website to be able to subscribe to keep up-to-date with any changes to my website.
The subscribe form will be in the _Subscribe.cshtml and this partial view will be called in the footer in the _Layout.cshtml.
This is because I don't want the subscribe view to be accessed directly through the url.
Is this a good or bad approach?
Upvotes: 2
Views: 2269
Reputation: 22168
It sure can, and I personally feel it's a perfectly sound approach! If you do specify a model for a partial, however, it is REQUIRED! Some folks like to hang a child model object off their main page model, then pass it into the partial, but I like being explicit about it.
@await Html.PartialAsync("Shared/_MobileBackNav", new MobileBackNavOptions { ShowBackButton = false })
Upvotes: 2