【发布时间】:2014-03-18 08:19:56
【问题描述】:
我正在尝试列出数据库中显示的数据,我创建了一个 ViewingGoals 类并在 ViewingGoalsBusinessLayer 类中实现其业务逻辑,代码如下
查看目标.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BusinessLayer
{
public class ViewingGoals
{
public string Goal { get; set; }
}
}
查看GoalsBusinessLayer.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using BusinessLayer;
namespace BusinessLayer
{
public class ViewingGoalsBusinessLayer
{
public void ViewData(ViewingGoals viewgoal)
{
try
{
string Connectionstring = ConfigurationManager.ConnectionStrings["Connectionstring"].ConnectionString;
List<ViewingGoals> viewgoals = new List<ViewingGoals>();
using (SqlConnection con = new SqlConnection(Connectionstring))
{
SqlCommand cmd = new SqlCommand("ViewGoal", con);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
//ViewingGoals viewgoal = new ViewingGoals();
viewgoal.Goal = rdr["Goal"].ToString();
viewgoals.Add(viewgoal);
}
}
}
catch (Exception ex)
{
throw ex;
}
}
}
}
我的控制器代码是:
查看目标控制器.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BusinessLayer;
namespace AppraisalManagementSystemFinal.Controllers
{
public class ViewingGoalsController : Controller
{
//
// GET: /ViewingGoals/
public ActionResult ViewingGoals()
{
ViewingGoalsBusinessLayer viewinggoalsbusinessLayer = new ViewingGoalsBusinessLayer();
List<ViewingGoals> viewgoals = viewinggoalsbusinessLayer.viewgoal.ToList();
return View(viewgoals);
}
}
}
在那个控制器中,我试图从 ViewingGoalBusinessLayer 访问对象 列出 viewgoals = 查看目标businessLayer.viewgoal.ToList();我收到错误,因为不包含 viewgoal 的定义。
请帮助我克服它。
【问题讨论】:
标签: asp.net-mvc c#-4.0