Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.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/5/spring-mvc/2.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
Asp.net mvc 4 在mvc4中获取视图上的属性_Asp.net Mvc 4 - Fatal编程技术网

Asp.net mvc 4 在mvc4中获取视图上的属性

Asp.net mvc 4 在mvc4中获取视图上的属性,asp.net-mvc-4,Asp.net Mvc 4,我有一个mvc4 c#razor web应用程序。 是否可以添加从视图中可用的属性 比如System.Security.Principal的“用户”。 我可以开始在视图中编写以下代码: @if(User.Identity) ... bla bla bla 我有一门课: public class UserModel { public int UserId { get; set; } public int CustomerId { get; set; } public strin

我有一个mvc4 c#razor web应用程序。 是否可以添加从视图中可用的属性

比如System.Security.Principal的“用户”。 我可以开始在视图中编写以下代码:

@if(User.Identity) ... bla bla bla
我有一门课:

public class UserModel
{
   public int UserId { get; set; }
   public int CustomerId { get; set; }
   public string UserName { get; set; }
}
现在我在BaseController类中有一个名为“UserInfo”的属性,所有控制器都从该属性继承。 守则:

public UserModel UserInfo
{
    get {
        if (_userInfo == null)
        {
          ...fill user info
        }
        return _userInfo;
    }
}
我不想将其作为@model传递,但仍然可以在视图中使用它
@UserInfo我该怎么做?

你可以使用ViewBag,但你不想将其添加到模型中有什么原因吗?1.我有很多视图,不想添加每个模型2.我不喜欢ViewBag,因为它是动态的。有没有一种方法可以像在“用户”属性视图上一样实现它?