asp.net mvc 读取数据的问题
varsta1=map.FindByLocation(float.Parse(st.la.ToString()),float.Parse(st.lo.ToString()...
var sta1= map.FindByLocation(float.Parse(st.la.ToString()), float.Parse(st.lo.ToString()));
ViewData["stations"] = sta1;
相关函数FindByLocation。
public IQueryable<Station> FindByLocation(float la,float lo)
{
var stations = from station in FindUpcomingDinners()
join i in db.NearestStation(la, lo)
on station.stid equals i.stid
select station;
return stations;
}
怎么我读到页面上就变成了数据库操作字符。
SELECT [t0].[stid] AS [stID], [t0].[title] AS [Title], [t0].[la] AS [Latitude], [t0].[lo] AS [Longitude], [t0].[bdate] AS [Description] FROM [dbo].[Stations] AS [t0] INNER JOIN [dbo].[NearestStation](@p0, @p1) AS [t1] ON [t0].[stid] = [t1].[stid] ORDER BY [t0].[stid] 展开
ViewData["stations"] = sta1;
相关函数FindByLocation。
public IQueryable<Station> FindByLocation(float la,float lo)
{
var stations = from station in FindUpcomingDinners()
join i in db.NearestStation(la, lo)
on station.stid equals i.stid
select station;
return stations;
}
怎么我读到页面上就变成了数据库操作字符。
SELECT [t0].[stid] AS [stID], [t0].[title] AS [Title], [t0].[la] AS [Latitude], [t0].[lo] AS [Longitude], [t0].[bdate] AS [Description] FROM [dbo].[Stations] AS [t0] INNER JOIN [dbo].[NearestStation](@p0, @p1) AS [t1] ON [t0].[stid] = [t1].[stid] ORDER BY [t0].[stid] 展开
2个回答
展开全部
你的 stations 对象 是个LINQ对象。
下面的 SELECT [t0].[stid] AS [stID], [t0].[title] AS [Title], [t0].[la] AS [Latitude], [t0].[lo] AS [Longitude], [t0].[bdate] AS [Description] FROM [dbo].[Stations] AS [t0] INNER JOIN [dbo].[NearestStation](@p0, @p1) AS [t1] ON [t0].[stid] = [t1].[stid] ORDER BY [t0].[stid]
就是LINQ转换的SQL 语句。
做法:
1:aspx 页面 : System.Web.Mvc.ViewPage<Station>
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Station>" %>
ViewPage 是一个泛型的类。 你指定下你的Model Station。
2:<%: Html.LabelFor(model => model.属性) %>
属性 应该是你定义的Station Model 的属性。 自己去替换吧。
下面的 SELECT [t0].[stid] AS [stID], [t0].[title] AS [Title], [t0].[la] AS [Latitude], [t0].[lo] AS [Longitude], [t0].[bdate] AS [Description] FROM [dbo].[Stations] AS [t0] INNER JOIN [dbo].[NearestStation](@p0, @p1) AS [t1] ON [t0].[stid] = [t1].[stid] ORDER BY [t0].[stid]
就是LINQ转换的SQL 语句。
做法:
1:aspx 页面 : System.Web.Mvc.ViewPage<Station>
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Station>" %>
ViewPage 是一个泛型的类。 你指定下你的Model Station。
2:<%: Html.LabelFor(model => model.属性) %>
属性 应该是你定义的Station Model 的属性。 自己去替换吧。
更多追问追答
追问
1.Inherits="System.Web.Mvc.ViewPage" 应该指定了。
2.Model.stid.是要查找的车站的车站号,是正常的。我就是想用viewdada储存和查找车站相近的车站数据。
我是新手很多不明白说错了见谅。
追答
ViewData 要从 Controller cs代码 后台给赋值
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询