これはコントローラーの私のコードです:
EApproveEntities db = new EApproveEntities();
DocumentDAO dataDocument = new DocumentDAO();
DocumentTypeData dataTypeDocument = new DocumentTypeData();
public void CreateDropDownListInDocument()
{
dataTypeDocument.GetDocumentType();
IEnumerable<SelectListItem> listTypeDocument = new SelectList(dataTypeDocument.documentType, "Key", "Value");
IEnumerable<SelectListItem> listPriorityDocument = new SelectList(dataDocument.Priority, "Key", "Value");
IEnumerable<SelectListItem> listStatusDocument = new SelectList(dataDocument.Status, "Key", "Value");
ViewBag.dataTypeDocument = listTypeDocument;
ViewBag.dataPriorityDocument = listPriorityDocument;
ViewBag.dataStatusDocument = listStatusDocument;
}
public ActionResult Index()
{
return View();
}
[HttpGet]
public ActionResult CreateDocument()
{
CreateDropDownListInDocument();
Document document = new Document();
return this.View(document);
//return this.View();
}
[ActionName("CreateDocument")]
[AcceptVerbs(HttpVerbs.Post)]
[Multiple_Button(Name = "Document", Value = "Cancel")]
public ActionResult Cancel()
{
return RedirectToAction("ListDocument");
}
//[ActionName("CreateDocument")]
[AcceptVerbs(HttpVerbs.Post)]
[Multiple_Button(Name = "Document", Value = "Create")]
public ActionResult CreateDocument(Document model,FormCollection formCollection)
{
CreateDropDownListInDocument();
return View(model);
}
ビューのコードでこれ:
<table class="tablestyle">
<tr>
<td >
<div>
@Html.LabelFor(model => model.NameOfDocument)
</div>
</td>
<td>
@Html.TextBoxFor(model => model.NameOfDocument, new { @class = "input-textbox" })
@*@Html.ValidationMessageFor(model => model.NameOfDocument);*@
</td>
</tr>
<tr>
<td >
<div>
@Html.Label("Status")
</div>
</td>
<td>
@Html.DropDownListFor(model => model.Status,
(IEnumerable<SelectListItem>)@ViewBag.dataStatusDocument, new { @class = "combobox_style" })
</td>
</tr>
<tr>
<td >
<div>
@Html.Label(" Priority")
</div>
</td>
<td>
@Html.DropDownListFor(model => model.Priority,
(IEnumerable<SelectListItem>)@ViewBag.dataPriorityDocument, new { @class = "combobox_style" })
</td>
</tr>
<tr>
<td >
<div>
@Html.Label(" Type of Document")
</div>
</td>
<td>
@Html.DropDownListFor(model => model.DocumentType,
(IEnumerable<SelectListItem>)@ViewBag.dataTypeDocument, new { @class = "combobox_style" })
</td>
</tr>
<tr>
<td >
<div>
@Html.Label("Path forder")
</div>
</td>
<td>
@Html.TextBoxFor(model => model.PathFolder,new {@Type="file"})
@* @Html.ValidationMessageFor(model => model.PathFolder)*@
</td>
</tr>
<tr>
<td>
@Html.Label("Note")
</td>
<td>
@Html.TextAreaFor(model => model.Note, new { @class = "textarea_style" })
@*@Html.ValidationMessageFor(model => model.Note)*@
</td>
</tr>
<tr>
<td>
<div class="style_button">
<input type="submit" class="t_button" value="Create" name="Document"/>
</div>
</td>
<td>
<div class="style_button">
<input type="submit" class="t_button" value="Cancel" name="Document"/>
</div>
</td>
</tr>
</table>
私はすべての検証に近かった。そして、EntityFramwork のモデルを使用します。検証はありません。しかし、これは結果です:
何もしないのになぜチェック検証なのかわかりません。これは私にいくつかのエラーが発生するためです。ありがとう!