2016-08-19 50 views
0

我試圖在asp網絡mvc中學習一些東西。如何在asp網絡控制器中使用自定義方法mvc

我無法處理問題。

我有一個像

public class trenMethod 
{ 
    public testDBContex db; 
    public List<IsSoSu> ListAll() 

    { 
     var Name= from a in db.test1 
        from b in db.test2 
        where a.Name== b.Name 
        select new IsSoSu() 
        { 
         NameLast=a.Name, 
         MidNameLast=a.MidName, 
         SurnameLast=b.Surname 
        }; 
     return Name.ToList(); 
    } 

它沒關係與自定義類。但是當我想在控制器中使用這種方法時,該方法似乎並沒有。

public ActionResult IndexTrEn() 
    { 
     trenMethod. <there is nothing in here> (i expect that trenMethod.ListAll(); but there is nothing except "Equals, ReferenceEquals") } 

我在哪裏犯錯?

+0

請注意,模型 - 視圖 - 控制器標記是關於模式的問題。 ASP.NET-MVC實現有一個特定的標籤。 –

+0

這裏沒有什麼,因爲你的'ListAll'方法不是靜態的,你試圖把它稱爲它。 –

回答

0

您需要實例化類和使用對象:

public ActionResult IndexTrEn() 
{ 
     var tm = new trenMethod(); 
     tm.ListAll(); 
     ... 
} 
相關問題