I am attempting to use the remote data annotation for the first time in MVC 3.
I am missing something simple. The setup is not firing the controller action at all and I’m not seeing the issue off hand.
I am attempting to validate username for uniqueness.
Here is the code setup.
View Code
@Html.Raw(Html.Script("jquery.validate.min.js"))
@Html.Raw(Html.Script("jquery.validate.unobtrusive.min.js"))
<tr>
<td class="editor-label">@Html.LabelFor(model => model.UserName):</td>
<td class="editor-field">@Html.EditorFor(model => model.UserName)</td>
<td>@Html.ValidationMessageFor(model => model.UserName)</td>
</tr>
ViewModel Code
[DisplayName("Username")]
[StringLength(100)]
[Remote("CheckIfUsernameExists", "UserProfile", ErrorMessage = "This username is taken. Please enter a different user name.")]
public string UserName { get; set; }
Controller Code
[HttpGet]
public JsonResult CheckIfUsernameExists(string userName)
{
return Json("false");
}
Check you setting, the client validation and the unobtrusive should be enabled
with that the following code should work