<script src="/Scripts/jquery-1.6.2.min.js" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
<script src="/Scripts/jquery.validate.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery.validate.unobtrusive.min.js" type="text/javascript"></script>
@model Izdivac.Models.User
@using(Html.BeginForm("Basics", "User", FormMethod.Post , new { id="aboutme"}))
{
@Html.ValidationSummary(true)
<fieldset>
<ul>
<li>
<label>Username</label>
@Html.TextBoxFor(m => m.Username, new {@class = "input-text size-xl"})
@Html.ValidationMessageFor(model => model.Username)
</li>
<li>
<label>First Name</label>
@Html.TextBoxFor(m => m.FirstName, new {@class = "input-text size-xl"})
@Html.ValidationMessageFor(model => model.FirstName)
</li>
<li>
<label>Last Name</label>
@Html.TextBoxFor(m => m.LastName, new {@class = "input-text size-xl"})
@Html.ValidationMessageFor(model => model.LastName)
</li>
<li>
<label>Gender</label>
@Html.EnumDropDownListFor(m => m.BasicInfo.Gender)
</li>
<li>
<input type="submit" class="input-button" />
</li>
</ul>
</fieldset>
}
<script type="text/javascript">
$(function () {
$('#aboutme').submit(function () {
$.ajax({
url: this.action,
type: this.method,
data: $(this).serialize(),
success: function (result) {
$('#ShowResultHere').html(result.s);
}
});
return false;
});
});
</script>
我正在尝试在不访问服务器并失败的情况下进行客户端验证。
我怎样才能解决这个问题?为什么会失败?
编辑:
这是模型:
public class User
{
public int Id { set; get; }
[StringLength(40)]
[Required]
public string FirstName { set; get; }
[StringLength(40)]
[Required]
public string LastName { set; get; }
[StringLength(100)]
[Required]
public string FullName { set; get; }