Heey,보기 오류 @Foreach (VAR 항목 ...) 모델/컨트롤러 /보기
나는 것 같다 문제 바보하지만 난 메신저가 내려다 보이는 생각하는 이유를 알고 난 그냥 문제를 해결할 수 없으며, 내가 해달라고 그래서 나는 새로운 눈 세트가 필요하다.
namespace LaatsteStudentWebAPI.Models
{
public class Student
{
public int StudenNr { get; set; }
public string Naam { get; set; }
public string Woonplaats { get; set; }
public string Adres { get; set; }
public int TelefoonNr { get; set; }
public string School { get; set; }
}
}
그리고 컨트롤러 :
namespace LaatsteStudentWebAPI.Controllers
{
public class ArticleController : Controller
{
private List<Student> students = new List<Student>();
private int _nextId = 1;
SqlConnection con;
SqlDataAdapter da;
DataSet ds = new DataSet();
public ActionResult Index()
{
SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["DefaultConnection"].ToString());
da = new SqlDataAdapter("SELECT StudentNr, Naam, Woonplaats, Adres, TelefoonNr, School FROM [Table] ORDER BY StudentNr DESC", con);
da.Fill(ds);
foreach (DataRow dr in ds.Tables[0].Rows)
{
students.Add(new Student() { StudenNr = int.Parse(dr[0].ToString()), Naam = dr[1].ToString(), Woonplaats = dr[2].ToString(), Adres = dr[3].ToString(), TelefoonNr = int.Parse(dr[4].ToString()), School = dr[5].ToString() });
}
return View(students);
}
}
}
그리고보기 :
나는 모델 클래스를 얻었다 이제@model IEnumerable<LaatsteStudentWebAPI.Models.Student>
@{
ViewBag.Title = "Index";
}
<h2>This is the Index</h2>
<table>
<thead>
<tr>
<td>StudentNummer</td>
<td>Naam</td>
<td>Woonplaats</td>
<td>Adres</td>
<td>Telefoonnummer</td>
<td>School</td>
</tr>
</thead>
@foreach (var item in LaatsteStudentWebAPI.Models.Student)
{
<tr>
<td>@item.StudenNr</td>
<td>@item.Naam</td>
<td>@item.Woonplaats</td>
<td>@item.Adres</td>
<td>@item.TelefoonNr</td>
<td>@item.School</td>
</tr>
}
</table>
내 문제입니다 나는 그것을 다의 외모를 실행할 때 좋아, (난 그 지저분한 코드를 알고 있지만 작동하도록) 하지만이 문제가 발생/오류.
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0119: 'LaatsteStudentWebAPI.Models.Student' is a 'type', which is not valid in the given context
Line 20:
Line 21:
Line 22: @foreach (var item in LaatsteStudentWebAPI.Models.Student)
Line 23: {
Line 24: <tr>
은 작은 내가 생각하는 문제와 나는 너희들이 나를 도와 어차피 희망을 해결할 희망 쉽게하는 잘못된 무슨 일.
점점이 오류 'System.NullReferenceException'형식의 예외가 App_Web_jkxy3fxw.dll에서 발생하지만 추가 정보 사용자 코드에서 처리되지 않은 : 인스턴스에 개체 참조가 설정되지 않음 개체의 –
어디서이 오류가 발생 했습니까? – afzalulh
같은 줄에 Model이라는 단어가 있습니다. 그래서 코드를 @foreach (Model의 LaatsteStudentWebAPI.Models.Student item) 으로 변경했지만 여전히 동일한 오류가 발생했습니다. –