2014-09-10 229 views
0
public class property 
{ 
    public int Id { get; set; } 
    public string UserId { get; set; } 

    [Required(ErrorMessage = "Enter your name")] 
    public string Name { get; set; } 

    [Required(ErrorMessage = "Enter your Email")] 
    public string Email { get; set; } 
    public string PostedBy { get; set; } 

    [Required(ErrorMessage = "Enter the mobile no")] 
    public Int64 Mobile { get; set; } 
} 

以下是需要实施验证的cshtml页面。客户端验证不起作用Mvc

@model Property.Models.property 


     @ { ViewBag.Title = "Create"; 
     Layout = "~/Views/Shared/_UserProperty.cshtml"; } 


<h2>Post Property</h2> 
     @using (Html.BeginForm("Create", "Listings", FormMethod.Post, new { enctype = "multipart/form-data" })) 
{  

    @Html.ValidationSummary(true) 

    <fieldset> 
     <article class="bs-docs-social-body"> 
      <section class="container"> 
       <div class="form-box-container"> 
        <div class="form-box-left"> 
         <h5>* Name :</h5> 
         @*@Html.EditorFor(model => model.Name)*@ 
         @Html.Editor("Name", @ViewData["Name"]) 
         @Html.ValidationMessageFor(model => model.Name) 
         <br> 
         <input type="radio" class="postedby" name="postedby" id="Builder" value="Builder" /> I am the Builder 
      <input type="radio" class="postedby" name="postedby" id="Agent" value="Agent" /> I am the Agent 
      <input type="radio" class="postedby" name="postedby" id="Owner" value="Owner" /> I am the Owner 

        </div> 
        <div class="form-box-right"> 
         <h5>* Email Address :</h5> 
         @*@Html.EditorFor(model => model.Email)*@ 
         @Html.Editor("Email", @ViewData["Email"]) 
         @Html.ValidationMessageFor(model => model.Email) 

        </div> 
       </div> 
       <div class="form-box-container"> 
        <div class="form-box-left"> 
         <h5>* Mobile No :</h5> 
         <select class="drop-item"> 
          <option>India (+91)</option> 
         </select> 
         @*<input type="text" name="Mobile" onkeypress="CheckNumeric(event);" maxlength="10" />*@ 
         @Html.Editor("Mobile", @ViewData["Mobile"]) 
         @Html.ValidationMessageFor(model => model.Mobile) 
         <br> 
        </div> 

       <div class="form-box-container"> 

        <input type="submit" name="Post" value="Post" class="btm-bg" /> 

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

<script type="text/javascript" src="~/Scripts/jquery.validate.min.js"></script> 
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js"></script> 
<script type="text/javascript" src="~/Scripts/jquery.validate.unobtrusive.min.js"></script> 

我不知道问题出在哪里。我也改变了我的模型以及所需的消息,但是仍然没有发生变化,并且在提交帖子后按钮后发生没有客户端验证的情况。

+0

你包括的jquery.js文件还..? – 2014-09-10 09:22:55

+0

嗨Karthikeya ..是的,我已经把它们包含在内..看到更新的问题 – 2014-09-10 09:24:04

+0

首先添加jquery,然后验证脚本。此外,在您的web.config应用程序设置中,您是否有 ? – SSA 2014-09-10 09:24:58

回答

2

试试你的js,呼吁该序列

<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js"></script> 
<script type="text/javascript" src="~/Scripts/jquery.validate.min.js"></script> 
<script type="text/javascript" src="~/Scripts/jquery.validate.unobtrusive.min.js"></script> 
+0

我应该在逻辑中添加什么来保存?我的意思是提交按钮本身取所有的值。 – 2014-09-10 09:43:47

+0

@Smokingmonkey尝试更改js文件validate.min.js和jquery.js的顺序。在按下F12键后检查是否有任何错误 – 2014-09-10 09:51:42

+0

@Smokingmonkey请再次检查答案我为您编辑它。 – 2014-09-10 09:54:06