我无法从数据库中获取存储过程的结果并在视图中显示。在数据库中,存储过程运行良好。
我的MsSQL存储过程
ALTER PROCEDURE [dbo].[Search]
(
@param1 varchar(max),
@param2 varchar(max),
@param3 varchar(max),
@param4 varchar(max)
)
AS
BEGIN
select BusinessLogo,BusinessTitle,Details,ProfileUrl,Location,Country from ClientBusinesses where location like '%'+@param1+'%' and location like '%'+@param2+'%'
and location like '%'+@param3+'%' and location like '%'+@param4+'%'
END
我执行存储过程的控制器代码
我尝试使用以下代码,但在ViewBag中无法看到数据。在ViewBag上使用foreach循环时出现错误,错误信息为“列BusinessLogo不存在”,但是在存储过程中可以看到我正在获取BusinessLogo列,其他列也有类似的错误。
ViewBag listdata = db.Search(Country, state, city, str);
我也尝试了以下代码 -
List<ClientBusiness> listd=new List<ClientBusiness>();
listd=db.Search(Country, state, city, str);
但它会报错。
Error 2 Cannot implicitly convert type 'System.Data.Entity.Core.Objects.ObjectResult<string>' to 'System.Collections.Generic.List<PromoteMyName.ClientBusiness>' F:\Desktop DATA\Desktop 23 Feb\PromoteMyName\PromoteMyName\Controllers\HomeController.cs 135 23 PromoteMyName
我在视图中使用以下简单代码
@foreach(var item in ViewBag.listdata)
{
}
这是通过ViewBag将从SP获取的数据传递到视图可能吗?