2013-05-02 52 views
0

我在我的控制器中有一個委託我想將其傳遞給我的視圖以進入我的設置。如何將委託對象傳遞給MVC Views。

我曾嘗試將代表分配給ViewData [「delegateFunction」] = delegateFunction;

,但同樣是無效的想法..

我知道這是一個基本的問題。但只是瞭解代表。

在此先感謝, saravanakumar。

+1

請停止將「ASP.NET MVC」簡稱爲「MVC」。一個是框架,而另一個是獨立於語言的設計模式。這就像打電話給IE - 「互聯網」 – 2013-05-03 23:02:30

回答

0

我使用模型類,將委託給視圖:

型號

public class ExampleModel 
{ 
    public Func<string, string> getUIName { get; set; } 
} 

方法聲明

public string concreteMethod_GetUIName(string text) 
{ 
    return text; 
} 

控制器

public ActionResult Index() 
{ 
    ExampleModel model = new ExampleModel { getUIName = concreteMethod_GetUIName }; 

    return View(model); 
} 

查看

@model ExampleModel 

@Model.getUIName("sample text")