嗨,
我有一个返回表的函数,我想显示这个列表中的表格-注意:该函数已成功执行。
我的功能
ALTER function [dbo].[VLOUL]
(
@LID int
)
RETURNS TABLE
As
Return
Select Users.UserName,Product.PName,Users.SK,Users.Brand,Users.CN,Users.SN,Users.AT,Users.Ref,Users.DC
from Users
INNER JOIN Product ON Product.PID = Users.PID
where Users.UID= @LID
控制器
public ActionResult Details(int S)
{
SLMEntitiesDB dbContext = new SLMEntitiesDB();
List<User> UList = dbContext.Users.Where(U => U.LID == S).ToList();
return View(UList);
}
我如何以某种方式显示它
在此处查看答案:Display List in a View MVC
解决方案很简单,您需要在视图内使用模型并相应地创建一个剃刀模板。
@model IEnumerable<UList>
@{
ViewBag.Title = "Title";
}
@foreach (var item in Model)
{
<div>
@item.Name
<hr />
</div>
}
因此,您的控制器不使用您创建的SQL。我建议您检查一下这两个链接:
我可能会按照他的方式来做:
var modelQuery =
from u in Users
from p in Products.Where(p => p.PID == u.PID).DefaultIfEmpty() **// NOTE: this does not seems to bee a good relation, I'd assume a NxN relation with a ternary table, but this is what you got in your SQL**
select new {
UserName = u.UserName,
PName = p.PName
};
var model = modelQuery.ToList(); // NOTE: in debugger you can examine the select that is described via the modelQuery and you also do not need to execute the query here, as returning modelQuery for the view is also an option.
我建议您: