Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass variable into layout in .NET?

My aplication have walls with notes. I wish to put on layout name of active wall. How to do that? I know that on front-end I can use just @Model... but who sends this model? Also better idea is store this information in session variable or create another property in user database?

EDIT: I use .NET Core 1.1.

like image 454
Maciek Drabicki Avatar asked Oct 26 '25 23:10

Maciek Drabicki


1 Answers

If you are talking about the _Layout.cshtml then you could place the following in _Layout.cshtml:

@RenderSection("layoutName", required: false)

Any view which inherits this layout can now add code to this section.

SomeOtherView.cshtml:

@section layoutName{
   <h1>@Model.LayoutName</h1>
}
like image 83
KevDevMan Avatar answered Oct 29 '25 17:10

KevDevMan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!