Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在MVC中的标签中显示正确的用户名_C#_Html_Asp.net Mvc - Fatal编程技术网

C# 在MVC中的标签中显示正确的用户名

C# 在MVC中的标签中显示正确的用户名,c#,html,asp.net-mvc,C#,Html,Asp.net Mvc,我的姓氏是“韦伯斯特”,但我想要NSantagata(我名字和姓氏的首字母)或Fieldaero\nicola.santagata 我怎么能这么做? 这是我的代码: 在控制器中: var userName = Request.RequestContext.HttpContext.User.Identity.Name; ViewBag.Name = userName; 在视图中: @Html.Label((string)ViewBag.Name) 如果我使用code@Request.Reque

我的姓氏是
“韦伯斯特”
,但我想要
NSantagata
(我名字和姓氏的首字母)或
Fieldaero\nicola.santagata

我怎么能这么做? 这是我的代码:

控制器中:

var userName = Request.RequestContext.HttpContext.User.Identity.Name;
ViewBag.Name = userName;
视图中

@Html.Label((string)ViewBag.Name)
如果我使用code
@Request.RequestContext.HttpContext.User.Identity.Name直接从视图中执行此操作

我得到了我想要的,即
Fieldaero\nicola.santagata
,但我不知道如何在控制器中获得相同的结果。然后,我将使用控制器中的值来执行其他代码。

这感觉我们需要一些对象的
LastName
FirstName
属性的更多信息。viewbag.name可能在管道中的某个位置被覆盖。asp.net mvc第1课:永远不要使用“viewbag”,制作一个viewmodel。你能更清楚地说明我可以做些什么来取回“NSantagata”或“FIELDARO\nicola.santagata”吗?我会在标签上显示。非常感谢。