将值从Controller传递给类asp.net MVC3.0

时间:2011-03-05 10:15:12

标签: asp.net-mvc-3

我有一个Controller,它从数据库接收值作为输出参数,我希望将该值传递给创建的.cs页面并在那里使用该值。可以请你帮我知道如何通过从控制器到类的值。 感谢....

1 个答案:

答案 0 :(得分:0)

在控制器内部,您可以通过将从数据库中检索的值作为参数传递来实例化该类并在其上调用一些方法:

public ActionResult Index()
{
    string value = ... // retrieve the value from database

    // instantiate the class
    SomeClass someClass = new SomeClass();

    // call some method and pass the value
    someClass.SomeMethod(value);

    return View();
}