2011-12-16 46 views
1

我已经尝试创建登录表单,并且还想显示我已存储在数据库中的用户登录配置文件。但是,我不知道如何从模型或控制器中做到这一点。显示数据库中的用户配置文件

我已将所有用户信息存储在数据库的Customers表中。

这是用户模型的代码:

public IList<Customer> GetProfileCustomer(string name) 
    { 
     var list_customer = from c in DataContext.Customers 
          where c.WebAccount == name 
          select c; 
     return list_customer.ToList(); 
    } 

而且这是我的AccountController:

public ActionResult ShowProfile() 
    { 
     return View(); 
    } 

我想,我在我的模型中写道,在我看来,以显示结果。

回答

3

传递功能视图模型的结果:

public ActionResult ShowProfile() 
    { 
     ViewData.Model = GetProfileCustomer("foo"); 
     return View(); 
    } 

那么你的观点会宣布@model IList<Customer>,你会访问只是这样的性质:

@foreach (var customer in Model) 
{ 
<p>@customer.FirstName</p> 
} 
+0

,当我在使用GetProfileCustomer()我控制器,它错误,它不包含在当前的上下文中。我准备将我的控制器中的所有模型导入。 – Nothing 2011-12-17 02:31:52

相关问题