ASP.NET MVC - "堆栈不足以继续安全地执行程序"在部分视图中

时间:2014-07-01 13:57:57

标签: c# asp.net-mvc-4 stack viewmodel

我试图通过部分视图添加一些医生记录。当我试图测试我的字段的最大长度时(例如,通过输入31个字母并且限制为30),我发现了以下错误:

  

堆栈不足以继续安全执行程序

这就是我正在做的事情(模型,视图和控制器):

型号:

public class DoctorViewModel
{
    public int DoctorId { get; set; }

    [Required(ErrorMessage="Champ requis")]
    [MaxLength(30)]
    public string DoctorLastName { get; set; }

    [Required(ErrorMessage = "Champ requis")]
    [MaxLength(30)]
    public string DoctorName { get; set; }
}

查看:

    <div id="addNewMedecin">
        @Html.Action("AddNewMedecin")
    </div>

    <div id="listMedecins">
        @Html.Action("ListMedecins")
    </div>

部分视图:

@using (Html.BeginForm("AddNewMedecin", "Home", FormMethod.Post))
{
    <fieldset id="fsMedecins">

        <div class="editor-label">
            Nom :
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(m => m.DoctorLastName)
            @Html.ValidationMessageFor(a => a.DoctorLastName)
        </div>
        <br />
        <div class="editor-label">
            Prénom :
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(m => m.DoctorName)
            @Html.ValidationMessageFor(a => a.DoctorName)
        </div>
        <input id="createNewMedecin" type="submit" name="Enregistrer" value="Enregistrer" />
    </fieldset>
}

控制器操作:

    public ActionResult Medecins()
    {
        return View();
    }

    [HttpGet]
    public ActionResult AddNewMedecin()
    {
        return PartialView();
    }

    [HttpPost]
    public ActionResult AddNewMedecin(DoctorViewModel dvm)
    {
        context = new SchedulingDataClassesDataContext();

        if (ModelState.IsValid)
        {
            DBMedecin newMedecin = new DBMedecin()
            {

                Nom = dvm.DoctorLastName,
                Prenom = dvm.DoctorName
            };

            context.DBMedecins.InsertOnSubmit(newMedecin);
            context.SubmitChanges();

            return RedirectToAction("Medecins");
        }

        return View("Medecins");
    }

任何想法的人?

0 个答案:

没有答案