내 데이터베이스 이러한 두 테이블 (프로젝트 및 테마)이 있습니다.여러 개의 선택된 확인란을 MVC4의 값으로 저장하는 방법
ProjectID와 테마가 포함 된 Project_Theme이라는 중간 테이블도 있습니다.
테마에는 약 15 개의 값이 미리 설정되어 있습니다.
나는 이러한 모든 주제를 체크 박스에 표시 할 수 있지만 데이터베이스에 저장하는 방법을 모르겠습니다.
public class Project
{
[Key]
public int ID { get; set; }
public string Type { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string Date { get; set; }
}
그리고 내 두 번째 모델 : 여기
private ProjectContext db = new ProjectContext();
//
// GET: /Project/
public ActionResult Index()
{
return View(db.Project.OrderBy(i => i.Name).ToList());
}
//
// GET: /Project/Create
public ActionResult Create()
{
var model = new Project();
ViewBag.Theme = db.Theme.ToList();
return View(model);
}
내 모델 : 여기
내 컨트롤러
: 마지막으로 여기
public class Theme
{
[Key]
public int ThemeID { get; set; }
public string Name { get; set; }
}
내 생성도이다
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<div style="text-align:center;padding:0 1px 0 1px" >
<table>
<tr align="left">
<td>
<div class="editor-label" style="width:110px">
<label for="theme">Theme(s)* : </label>
</div>
</td>
<td>
<div class="editor-field">
@foreach (var t in theme)
{
<label class="checkbox">
<input type="checkbox" name="theme" value="@t.ThemeID"> @c.Name
</label>
}
</div>
</td>
</tr>
<tr align="left">
<td>
<div class="editor-label">
@Html.LabelFor(model => model.Name)
</div>
</td>
<td>
<div class="editor-field focus">
@Html.TextBoxFor(model => model.Name, new { style = "width:410px" })
@Html.ValidationMessageFor(model => model.Name)
</div>
</td>
</tr>
.........
나를 도울 수있는 사람이 있다면
그래서, 내가 입심 또는 인정되고 싶지 않아 :)
데이터베이스에 연결하는 방법에 대한 자세한 정보를 제공 할 수 있습니까? 엔티티 프레임 워크를 사용하고 있습니까? – LiverpoolsNumber9
Web.config => DbContext에서 영향을 미치는 연결 문자열 System.Data.SqlClient => ProjectContext –
그렇다면 Entity 프레임 워크는 무엇입니까? – LiverpoolsNumber9