0
asp.net을 사용하여 bd에서 테이블로 채워진 모든 개체를 별도의 테이블 단락으로 나누는 방법은 아직 해결할 수 없지만 어떤 도움을 주시면 감사하겠습니다. 여기 지금 방법의 스크린 샷입니다 : enter image description hereASP.Net mvc5
그 내가이 웹에있을하는 방법 : 이것은 인덱스 페이지 내 표는
이다는
@{
ViewBag.Title = "Главная страница";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<table>
@foreach (var b in ViewBag.Events)
{
<tr>
<td style=" padding: 8px;"><p><h2>@b.Date</h2></p></td>
<td style=" padding: 8px;"><p><h2>@b.Time</h2></p></td>
</tr>
}
<tr>
<td style="border: solid 1px grey; color: red; text-align: center; "><p><h3>Title</h3></p></>
<td style="border: solid 1px grey; color: red; text-align: center; "><p><h3>Place</h3></p></td>
<td style="border: solid 1px grey; color: red; text-align: center; "><p><h3>Lecturer</h3></p></td>
</tr>
@foreach (var b in ViewBag.Events)
{
<tr style="padding: 80px;">
<td style="border: solid 1px grey; padding: 8px; background-color: #ddc9ee;"><p><h4>@b.Title</h4></p></td>
<td style="border: solid 1px grey; padding: 8px; background-color: #ddc9ee; "><p><h4>@b.Location</h4></p></td>
<td style="border: solid 1px grey; padding: 8px; background-color: #ddc9ee; "><p><h4>@b.Responsible</h4></p></td>
</tr>
}
</table>
<a href="CreateEvent" class="Button">Add Event</a>
홈 컨트롤러
using PhClub.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace PhClub.Controllers
{
public class HomeController : Controller
{
EventsContext db = new EventsContext();
public ActionResult Index()
{
IEnumerable<Event> events = db.Events;
ViewBag.Events = events;
return View();
}
[HttpGet]
public ActionResult CreateEvent()
{
return View();
}
[HttpPost]
public ActionResult CreateEvent(AddEvent addEvent)
{
db.AddEvents.Add(addEvent);
db.SaveChanges();
return View();
}
}
}
두 번째 질문 - 현재 ID가 하드 코드 된 ID로 새 이벤트를 추가 할 때 위의 방법으로 채워지지 않습니다 - 어디에서 잘못 되었습니까?
여기,
<body>
<div>
<h3>Form of event creation</h3>
<form method="post" action="">
@*<input type="hidden" value="@ViewBag.AddEventId" name="AddEventId" />*@
<table>
<tr>
<td><p>Enter Id of event :</p></td>
<td><input type="text" name="AddEventId" /> </td>
</tr>
<tr>
<td><p>Enter title :</p></td>
<td><input type="text" name="Title" /> </td>
</tr>
<tr>
<td><p>Date:</p></td>
<td><input type="text" name="Date" /> </td>
</tr>
<tr>
<td><p>Time :</p></td>
<td><input type="text" name="Time" /> </td>
</tr>
<tr>
<td><p>Address :</p></td>
<td>
<input type="text" name="Location" />
</td>
<tr>
<td><p>Lecturer:</p></td>
<td><input type="text" name="Responsible" /> </td>
</tr>
<tr><td><input type="submit" value="Send" /> </td><td></td></tr>
</table>
</form>
</div>
</body>
내가 사용하는 이벤트 입력에 대한 테이블
그것을 않았다! 데이빗 감사합니다. –