I was wondering if there is a way to specify a model for the _layout.cshtml file, I saw a lot of posts with the same question with people answering โalternativeโ solutions, not saying that this is impossible, and showing how exactly we could achieve of this
having some experience with web forms that I tried to port to MVC and often come across such questions, I found this site: http://blog.bitdiff.com/2012/05/sharing-common-view-model- data-in.html that partially solved my problem, but even they donโt associate their _layout.cshtml with @model, as far as I know, I have to specify a model for each view, if I want to access the SharedContext, please correct if I wrong
what I wanted to do was declare "@model Namespace.MyModel" on _layout.cshtml so that it could get its information on its own, instead of implementing a model for each view inheriting from LayoutModel
* I hope itโs clear to me basically, I wanted to know how I can declare the @model tag on _layout.cshtml so that it can access its own model.
with the solution I linked earlier (although this is not related to my question), I have to do: @ (((BaseController) ViewContext.Controller) .Context.Property) to get general information, and if I could just declare ( and use) @model instead, I could do the same by doing something like: @Model. Property *
as you can see, I am trying to transfer everything that I already know from webforms to MVC, and it is quite difficult for me, since I have to accept certain methods that are completely different from what I used for
early
source share