2011-12-16 25 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

相關問題