나는 문제가있다. 데이터베이스에서 데이터를 가져 와서 표 형식으로 cshtml을 보여줘야한다. .... 데이터를 볼 수는 있지만 코드가 보이지 않는다. 내가 프로그램을 실행할 때MVC3에서 cshtml의 눈금에 데이터를 표시하는 방법은 무엇입니까?
BugTracker Model
namespace Gridview_BugTracker.Models
{
public class BugTracker_DataHelper
{
public static List<BugTracker_DataHelper> GetList{get;set;}
public string projectName { get; set; }
public string Description { get; set; }
public string status { get; set; }
}
------------------------------
BugTracker Controller
public ActionResult Index()
{
Gridview_BugTracker.Models.BugTracker_DataHelper model = new BugTracker_DataHelper();
SqlConnection conn = new SqlConnection(@"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=BugTracker;Data Source=SSDEV6\SQLEXPRESS");
conn.Open();
SqlCommand dCmd = new SqlCommand("Select * from Projects", conn);
SqlDataAdapter da = new SqlDataAdapter(dCmd);
DataSet ds = new DataSet();
da.Fill(ds);
conn.Close();
for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
{
model.projectName = ds.Tables[0].Rows[i]["projectName"].ToString();
model.Description = ds.Tables[0].Rows[i]["Description"].ToString();
model.status = ds.Tables[0].Rows[i]["Status"].ToString();
}
return View(model);
}
Index.Cshtml
@model IEnumerable<Gridview_BugTracker.Models.BugTracker_DataHelper>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th>
ProjectName
</th>
<th>
Description
</th>
<th>
Status
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.projectName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Description)
</td>
<td>
@Html.DisplayFor(modelItem => item.status)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.projectName }) |
@Html.ActionLink("Details", "Details", new { id = item.Description }) |
@Html.ActionLink("Delete", "Delete", new { id = item.status })
</td>
</tr>
}
이 오류를 얻고있다
error
----------------
The model item passed into the dictionary is of type 'Gridview_BugTracker.Models.BugTracker_DataHelper',
but this dictionary requires a model item of type
'System.Collections.Generic.IEnumerable`1[Gridview_BugTracker.Models.BugTracker_DataHelper]'.
,
그래서 내가 잘못하고 오전 또는 내가 더 어떤 일을 추가해야 할 하나 개의 도움이 .....
당신이Gridview_BugTracker.Models.BugTracker_DataHelper
와보기를 보낼 수 있기 때문이다
그것은 많은 ........... – SoftwareNerd
@anilkumar를 감사했다 : 당신은 환영. 기꺼이 도와 드릴 수 있습니다. :) – Shyju