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页面。
@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 :(得分: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>