ASP.Net MVC 4 linq to viewbag [英] ASP.Net MVC 4 linq to viewbag
问题描述
我想从我的模型中获取一条记录,并将两个字段(或一个字符串)传递给视图。
我在互联网上发现了很多与我想要的相近的例子,但我找不到如何捕获一个记录和两个字段并传递给viewbag以便传递给视图。
如何让ViewBag.WelcomeSign显示用户的名字和姓氏?
我在Windows 7 64位计算机上使用Visual Studio 2010,C#,ASP.Net MVC 4。
这是我到目前为止的代码。
[CONTROLLER]
public class HomeController:Controller
{
private MyEntities db = new MyEntities();
< p style ="margin:0in; FONT-FAMILY:宋体; font-size:11pt">
public ActionResult Index()
{
ViewBag.WelcomeSign = db.Users.First( u => u.UserId.Contains(" 007"))。FirstName& .LastName;
return View();
}
[VIEW]
@ ViewBag.WelcomeSign
对于这些问题,ASP.NET MVC论坛是一个更好的地方:
http://forums.asp.net/1146.aspx/1?MVC
I want to get one record from my model and pass two fields (or one string) to the view.
I have found lots of examples on the internet that are close to what I want but I can't find how to capture one record and two fields and pass to viewbag for it to pass to view.
How do I get ViewBag.WelcomeSign to show the First and Last name of the user?
I am using Visual Studio 2010, C#, ASP.Net MVC 4, on a Windows 7 64 bit computer.
Here is my code so far.
[CONTROLLER]
public class HomeController : Controller
{
private MyEntities db = new MyEntities();
public ActionResult Index()
{
ViewBag.WelcomeSign = db.Users.First(u => u.UserId.Contains("007")).FirstName & .LastName;
return View();
}
[VIEW]
@ViewBag.WelcomeSign
The ASP.NET MVC forums is a better place for such questions: http://forums.asp.net/1146.aspx/1?MVC
这篇关于ASP.Net MVC 4 linq to viewbag的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!