我是.net mvc的新手,我正在使用Visual Studio 2012.我只想从控制器中的数据库表中获取数据并将此值存储到不同的变量中。例如:
public class TestController
{
public ActionResult TestMethod()
{
var model = some LINQ code;
}
}
现在我只想将此model
值存储到不同的变量中,例如string
,int
等,具体取决于必要的。
答案 0 :(得分:0)
首先,您必须了解有关 mvc 4 的更多信息。互联网上有很多教程。 check this out
以下是一些示例代码::
在您的控制器中:
public class testController
{
public ActionResult testMethod()
{
ViewBag.someData = // get data from database using Linq or SQL Query
// or you can use Model/ModelView
return View(model)
}
}
在你的视图(cshtml)::
中@{
var someData = ViewBag.someData; // now you can use this data in your cshtml file
}