如何将信息发送到布局?

问题描述 投票:-1回答:1

我想创建一个每次都将信息发送到布局的函数。

现在,我在布局中执行一些查询以使用System.Security.Principal.WindowsIdentity.GetCurrent()获取名称和用户,并查询数据库中的链接服务器,但是现在我想在Controller中创建一个“构造函数”,向我发送信息到视图。

希望您能帮助我:D或给我一个例子。

c# .net model-view-controller directoryservices
1个回答
0
投票

如果要向布局页面发送信息/数据,则可以为其使用会话。在我的项目中,我使用了Session变量,并且得到了预期的结果。下面是用控制器的动作方法编写的代码,

Session["UserName"] = entity.FirstName + " " + entity.LastName;

和LayoutPage,

<span class="font-bold">@HttpContext.Current.Session["UserName"].ToString()</span>
© www.soinside.com 2019 - 2024. All rights reserved.