0

我在两个字段电子邮件和 CNIC 上使用远程验证。远程验证正常工作,但是当我单击提交按钮表单时不发布。当我删除两个字段表单上的远程验证时,发布数据。

模型

Public class VMModel{ 
[Remote("Function","Controller",ErrorMessage = "The CNIC already exists")]    
public string CNIC { get; set; }
[Remote("Function2", "Controller", ErrorMessage = "The Email already exists")]
public string Email { get; set; }
}

控制器

 public JsonResult Function2(string Email)
    {
        bool IsExist = true;            
        if (Membership.GetUser(Email) != null)
        {
            IsExist = false;
        }

        return Json(IsExist, JsonRequestBehavior.AllowGet);
    }
    public JsonResult Function(string CNIC)
    {
        bool IsExist = true;
        if (GetUserByCNIC(CNIC) != null)
        {
            IsExist = false;
        }

        return Json(IsExist, JsonRequestBehavior.AllowGet);
    }

    [HttpPost]
    public ActionResult Create(VMModel model)
    {       

     return View(model);

    }

查看代码

<script src="<%: Url.Content("~/Scripts/jquery.validate.min.js") %>"type="text/javascript"></script>
<script src="<%: Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js") %>" type="text/javascript"></script>
<%using (Html.BeginForm("Create", "Controller", FormMethod.Post, new { enctype = "multipart/form-data"}))
 { %>


        <fieldset>                 
           <div class="inner_left">
                 <div class="editor-label">
                <%: Html.LabelFor(m => m.Email)%>
                </div>
                <div class="editor-field">
                <%: Html.TextBoxFor(m => m.Email)%>                
                <%:Html.ValidationMessageFor(m => m.Email)%>
            </div>
                <div class="clear"></div>  

                 <div class="editor-label">
                <%: Html.LabelFor(m => m.CNIC)%>
                </div>
                <div class="editor-field">
                <%: Html.EditorFor(m => m.CNIC)%>                
                <%:Html.ValidationMessageFor(m => m.CNIC)%>
            </div>
                <div class="clear"></div>   

            </div>              
               <div class="clear"></div>         
                </div>

       <div class="clear"></div>                
        <p style="text-align:left;margin-left: auto;margin-right: auto;width: 400px;">                                              
           <input type="submit" class="hrbutton" value="Create" />          
        </p>
    </fieldset>
<% } %>   

4

0 回答 0