1

这是我在控制器中的代码:

 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的模型。没有任何验证。但这是结果: 在此处输入图像描述

我不明白为什么当我什么都不做时它会检查验证。因为这让我犯了一些错误。谢谢!

4

0 回答 0