Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 验证表单缺少方法验证_C#_Asp.net Mvc - Fatal编程技术网

C# 验证表单缺少方法验证

C# 验证表单缺少方法验证,c#,asp.net-mvc,C#,Asp.net Mvc,我想在单击Save按钮并将表单保存到数据库中时,显示一个带有验证消息的模式窗口 Imex类 using System; using System.Collections.Generic; using WebApplication1.Models; using System.Linq; using System.Web; using WebApplication1.App_Data.DTOs; namespace WebApplication1.App_Data.DTOs { publ

我想在单击Save按钮并将表单保存到数据库中时,显示一个带有验证消息的模式窗口

Imex类

using System;
using System.Collections.Generic;
using WebApplication1.Models;
using System.Linq;
using System.Web;
using WebApplication1.App_Data.DTOs; 

namespace WebApplication1.App_Data.DTOs
{
    public class DataMessageDTO
    {
        public bool IsValid { get; set; }

        public bool IsInfo { get; set; }

        public string Message { get; set; }
    }
    public class ImexReportDTO
    {

        public ImexReportDTO(string question, int questionId, int opSpeId)
        {
            this.Id = 0;
            this.OpSpeId = opSpeId;
            this.Question = question;
            this.Response = "NON";
            this.Comment = null;
            this.Signatory = null;
            this.Date = null;
            this.QuestionId = questionId;
        }

        public ImexReportDTO(IMEXREPORTDEBUG k)
        {
            this.Id = k.Id;
            this.OpSpeId = k.OpSpeId;
            this.Question = k.Question;
            this.Response = k.Response;
            this.Comment = k.Comment;
            this.Signatory = k.Signatory;
            this.Date = k.Date;
            this.QuestionId = k.QuestionId;
        }

        public long Id { get; set; }

        public int OpSpeId { get; set; }

        public string Question { get; set; }

        public string Response { get; set; }

        public string Comment { get; set; }

        public string Signatory { get; set; }

        public DateTime? Date { get; set; }

        public int? QuestionId { get; set; }


    }
}
我的视图索引

 @model IEnumerable<WebApplication1.App_Data.DTOs.ImexReportDTO>
@Styles.Render("~/Content/themes/base/css", "~/Content/css")

    @{

        ViewBag.Title = "Index";
        var date = DateTime.Now.ToShortDateString();


    }

        <div class="form-horizontal">
            <h4 class="text-left">
                Bonjour, vous vous êtes bien connecté avec le numéro d'OT <span style="color:#077937">@(ViewBag.OT) </span>
            </h4>
        </div>
<div ajaxUpdateContainerId="gridContent" class="row">
    @using (Html.BeginForm("Valid","ImexReportDTOes", FormMethod.Post, new { id= ""}))
    {
        @Html.Hidden("returnUrl", Request.Url.ToString())

        @Html.AntiForgeryToken()
        @Html.ValidationSummary(true)
        <fieldset>
            <section class="panel panel-default" style="align-content:center;text-align:center; background-color:#e9e7e7">
                <section class="panel-heading panel-success" style="align-content:center; text-align:center">
                    <div class="panel-heading" style="text-align:center">

                        <h2 style="color:#280202;display:inline-block;text-align:center;">
                            Veuillez remplir le questionnaire pour le site "..." @(ViewBag.entite)
                        </h2>
                    </div>
                </section>
                <section class="panel-body" style="align-content:center; text-align:center">
                    <div class="form-group" style="align-content:center; text-align:center">
                        <div class="table-responsive" style="align-content:center; text-align:center">
                            <table id="table" class="=table table-responsive table-bordered table-hover nav nav-justifiedr" style="align-content:center; text-align:center; width:100%">

                                <thead class="panel-title bg-success" style="align-content:center">
                                    <tr>
                                        <th style="text-align:center">&nbsp;ID&nbsp;</th>
                                        <th style="text-align:center" class="control-label">&nbsp;OpSpeID&nbsp; </th>
                                        <th style="text-align:center" class="control-label">&nbsp;QUESTION&nbsp; </th>
                                        <th style="text-align:center" class="control-label">&nbsp;REPONSE&nbsp; </th>

                                        <th style="text-align:center" class="control-label"> &nbsp;COMMENTAIRE&nbsp; </th>
                                        <th style="text-align:center" class="control-label">&nbsp;SIGNATAIRE&nbsp;</th>
                                        <th style="text-align:center" class="control-label">&nbsp;QuestionId&nbsp;</th>
                                        <th style="text-align:center" class="control-label">&nbsp;DATE&nbsp;</th>
                                    </tr>
                                </thead>
                                <tbody class="panel-body">
                                    @foreach (var item in Model)
                                    {

                                        <tr>
                                            <td class="panel-heading bg-success">
                                                @Html.DisplayFor(modelItem => item.Id)
                                                @Html.ValidationMessageFor(modelItem => item.Id)
                                            </td>
                                            <td>
                                                @Html.DisplayFor(modelItem => item.OpSpeId, new { htmlAttributes = new { @class = "form-control", @rows = "3" } })
                                                @Html.ValidationMessageFor(modelItem => item.OpSpeId, "", new { @class = "form-group" })
                                            </td>
                                            <td>
                                                @Html.DisplayFor(modelItem => item.Question, new { htmlAttributes = new { @class = "form-control", @rows = "3" } })
                                                @Html.ValidationMessageFor(modelItem => item.Question, "", new { @class = "form-group" })
                                            </td>
                                            <td>

                                                <select>
                                                    @{
                                                        if (item.Response == "NON")
                                                        {
                                                            <option> @Html.DisplayFor(modelItem => item.Response, new { htmlAttributes = new { @class = "form-control", @rows = "3" } }) </option>
                                                            <option value="OUI"> OUI </option>
                                                            <option value="Sans Objet"> SANS OBJET </option>
                                                        }

                                                        else if (item.Response == "OUI")
                                                        {
                                                            <option> @Html.DisplayFor(modelItem => item.Response, new { htmlAttributes = new { @class = "form-control", @rows = "3" } }) </option>
                                                            <option value="NON"> NON </option>
                                                            <option value="Sans Objet"> SANS OBJET</option>
                                                        }
                                                        else
                                                        {
                                                            <option> @Html.DisplayFor(modelItem => item.Response, new { htmlAttributes = new { @class = "form-control", @rows = "3" } }) </option>
                                                            <option value="NON"> NON </option>
                                                            <option value="OUI"> OUI </option>
                                                        }
                                                    }

                                                </select>
                                                @Html.ValidationMessageFor(modelItem => item.Response, "", new { @class = "form-group text-danger" })
                                            </td>
                                            <td>
                                                @Html.TextAreaFor(model => item.Comment, new { htmlAttributes = new { @class = "form-control", @rows = "3", @textMode = "Multiline", @id = "Comment" } })
                                                @Html.ValidationMessageFor(modelItem => item.Comment, "", new { @class = "form-group text-danger", @id = "Comment" })
                                            </td>
                                            <td>
                                                @Html.DisplayFor(model => item.Signatory, new { htmlAttributes = new { @class = "form-control", @rows = "3" } })
                                                @Html.ValidationMessageFor(modelItem => item.Signatory, "", new { @class = "form-group" })
                                            </td>
                                            <td>
                                                @Html.DisplayFor(model => item.QuestionId, new { htmlAttributes = new { @class = "form-control", @rows = "3" } })
                                                @Html.ValidationMessageFor(modelItem => item.QuestionId, "", new { @class = "form-group" })
                                            </td>
                                            <td>
                                                @date
                                                @Html.ValidationMessageFor(modelItem => item.Date, "", new { @class = "form-group" })
                                            </td>
                                        </tr>
                                                        }
                                </tbody>
                            </table>
                        </div>
                    </div>
                </section>
                <section class="panel-footer panel-success">
                    <div class="form-group panel-success" style="text-align:center">

                        <button type="submit" class="form-group modal-link btn btn-success" id="enregistrer" value="enregistrer" data-toggle="modal" data-target="#modal-container"> <span class="glyphicon glyphicon-floppy-saved"></span> Enregister</button>
                        <button type="reset" class="form-group  btn btn-danger"> <span class="glyphicon glyphicon-floppy-remove"></span> Annuler</button>

                    </div>
                </section>

            </section>
        </fieldset>
                                                        }
</div>

    <!-- Modal -->
<div id="modal-container" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="padding-top:100px">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <div class="modal-title" id="myModalLabel"><h4>Message Modal</h4></div>
            </div>
            <div class="modal-body">
                @{
                    if (ViewBag.Comment == "")
                    {
                        <h4>
                            Veuillez remplir le champs Commentaire SVP
                        </h4>
                    }
                    else
                    {

                        <h4>
                            <span style="align-content:center ;color:darkorange"> Merci ! </span> Votre Questionnaire a bien était enregistré.
                        </h4>
                    }
                }
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div><!-- /.modal -->


@section Scripts {
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryval")
@Scripts.Render("~/bundles/bootstrap")
@Styles.Render("~/Content/bootstrap")
@Styles.Render("~/Content/bootstrap.min.css")
@Styles.Render("~/Content/css")
}
@model IEnumerable
@style.Render(“~/Content/themes/base/css”,“~/Content/css”)
@{
ViewBag.Title=“Index”;
var date=DateTime.Now.ToShortDateString();
}
您好,您愿意与我们联系吗
@使用(Html.BeginForm(“Valid”,“ImexReportDTOes”,FormMethod.Post,new{id=”“}))
{
@Hidden(“returnUrl”,Request.Url.ToString())
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
Veuillez Rempli网站“…”@(ViewBag.entite)
身份证件
OpSpeID
问题:
回应
评论
签名者
问题号
日期
@foreach(模型中的var项目)
{
@DisplayFor(modeleItem=>item.Id)
@Html.ValidationMessageFor(modelItem=>item.Id)
@DisplayFor(modeleItem=>item.OpSpeId,new{htmlAttributes=new{@class=“form control”,@rows=“3”})
@Html.ValidationMessageFor(modelItem=>item.OpSpeId,“,new{@class=“form group”})
@DisplayFor(modeleItem=>item.Question,new{htmlAttributes=new{@class=“form control”,@rows=“3”})
@Html.ValidationMessageFor(modelItem=>item.Question,“,new{@class=“form group”})
@{
如果(item.Response==“非”)
{
@DisplayFor(modeleItem=>item.Response,new{htmlAttributes=new{@class=“form control”,@rows=“3”})
是的
无对象
}
否则如果(item.Response==“OUI”)
{
@DisplayFor(modeleItem=>item.Response,new{htmlAttributes=new{@class=“form control”,@rows=“3”})
不
无对象
}
其他的
{
@DisplayFor(modeleItem=>item.Response,new{htmlAttributes=new{@class=“form control”,@rows=“3”})
不
是的
}
}
@Html.ValidationMessageFor(modelItem=>item.Response,“,new{@class=“form group text danger”})
@Html.TextAreaFor(model=>item.Comment,new{htmlAttributes=new{@class=“form control”、@rows=“3”、@textMode=“Multiline”、@id=“Comment”})
@Html.ValidationMessageFor(modelItem=>item.Comment,”,新{@class=“form group text danger”,@id=“Comment”})
@DisplayFor(model=>item.signature,new{htmlAttributes=new{@class=“form control”,@rows=“3”})
@Html.ValidationMessageFor(modelItem=>item.signature,“,new{@class=“form group”})
@DisplayFor(model=>item.QuestionId,new{htmlAttributes=new{@class=“form control”,@rows=“3”})
@Html.ValidationMessageFor(modelIte
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Xml;
using System.Web.UI.WebControls;
using WebApplication1.App_Data.DTOs;
using System.Web.Mvc;
using WebApplication1.App_Data.Repositories;
using WebApplication1.Models;
using FlashMessage;

namespace WebApplication1.Controllers
{
    public class ImexReportDTOesController : Controller
    {
        private WebApplication1Context db = new WebApplication1Context();


        // GET: ImexReportDTOesController
        [HttpGet]
        public ActionResult Index(
            string OT,
            string entite,
            string Comment
            )
        {

            ViewBag.user = Repository.GetLogonUser();
            ViewBag.OT = OT;
            ViewBag.entite = entite;
            int id = 0;
            ViewBag.Comment = Comment;

            if (OT != null && OT.Length > 0)
            {

                if (int.TryParse(OT, out id))
                {
                    var x = Repository.FindImexReport(id);


                    List<OpSpeDTO> opSpes = Repository.ExportOpSpe(id);

                    if (opSpes.Any() == false)
                    {
                    }
                    else if (opSpes.First().cas == null)
                    {
                    }
                    else
                    {
                        OpSpeDTO opSpe = opSpes.First();

                        if (opSpe.cas == 'A') opSpe.cas = '1';
                        if (opSpe.cas == 'B') opSpe.cas = '2';
                        if (opSpe.cas == 'C') opSpe.cas = '3';

                        if (opSpe.cas != '1' && opSpe.cas != '2' && opSpe.cas != '3' && opSpe.cas != '4' && opSpe.cas != '5')
                        {
                        }
                        else
                        {
                            if (x != null)
                            {

                                return View(Repository.FindImexReport(id));
                            }
                            else
                            {
                                return null;
                            }

                        }

                    }
                }
            }
           ViewBag.MessageErreur = "Le Numéro d'OT que vous avez saisi n'est pas correct !";
            return View("Error");
        }

     public PartialViewResult Valid()
      {
           List<string> errors;
           List<ImexReportDTO> reports = new List<ImexReportDTO>();
          var result = Repository.UpdateReport(reports, out errors);

          return PartialView( "Index", result);
       }

        [ValidateAntiForgeryToken]
        [HttpPost]
        public PartialViewResult Valid(ImexReportDTO imexReportDTO)
        {

            List<string> errors;
            List<ImexReportDTO> reports = new List<ImexReportDTO>();
            DataMessageDTO dataMessage = new DataMessageDTO();
            if (ModelState.IsValid)
            { 
                Repository.UpdateReport(reports, out errors);
                dataMessage.IsValid = true;
                dataMessage.Message = "saisie enregistre";
            }
            else
            {
                dataMessage.Message = "erreur";
            }
            ModelState.Clear();
            return PartialView("_DataMessage", dataMessage);
        }
        //   

        //  public ActionResult Index([Bind(Include = "Id,OpSpeId,Question,Response,Comment,Signatory,QuestionId")] ImexReportDTO imexReportDTO)
        //     {
        //      List<string> errors;
        //
        //       string user = Repository.GetLogonUser();

        //      List<ImexReportDTO> reports = new List<ImexReportDTO>();



        //       if (ModelState.IsValid)
        //     {


        //        Repository.UpdateReport(reports, out errors);
        //        this.db.ImexReportDTOes.Add(imexReportDTO);
        //     this.db.SaveChanges();
        //TempData["Msg"] = "Votre Questionnaire a bien était enregistré.";
        //       return this.RedirectToAction("Index");
        //    }

        //  this.ViewBag.Response = new SelectList(this.db.ImexReportDTOes, "Response", "", imexReportDTO.Response);

        //          return this.View(imexReportDTO);


        //  }


    }
}
 <script type="text/javascript">
    $(document).ready(function () {
        $(".btn.btn-danger").click(function (e) {
            e.preventDefault();
            var id = $(this).data("id");
            swal({
                title: "Are you sure?",
                text: "This record will be saved!",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "Yes, delete it!",
                closeOnConfirm: false
            },
            function (result) {
                if (result) {
                    swal("Saved!", "This record has be Saved.", "success");
                    $("form#" + id).submit();
                }
            });
        });
    });
</script>