Skip to content

Instantly share code, notes, and snippets.

@troufster
Created April 28, 2011 14:34
Show Gist options
  • Save troufster/946460 to your computer and use it in GitHub Desktop.
Save troufster/946460 to your computer and use it in GitHub Desktop.
MVC3 Ajax Validation
@using (Html.BeginForm("Create", "MyModel", FormMethod.Post, new { id = "CreateForm" }))
{
@Html.ValidationSummary(true)
<fieldset>
<legend>MyModel</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Property)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Property)
@Html.ValidationMessageFor(model => model.Property)
</div>
</fieldset>
}
$('#ajaxstuff').ajaxLink({
data: {},
success: function (data) {
$('#ajaxdiv').append(data);
$.validator.unobtrusive.parseDynamicContent('form');
}
});
@using(new MvcForm(ViewContext))
{
<div class="editor-label">
@Html.LabelFor(model => model.Property)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Property)
@Html.ValidationMessageFor(model => model.Property)
</div>
}
<input class="text-box single-line"
data-val="true"
data-val-required="This field is required!"
id="Property"
name="Property"
type="text"
value=""
/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment