Model
public class UserEntityViewModel
{
[Required(ErrorMessageResourceType = typeof(DCC.Main.Resources.Resources), ErrorMessageResourceName = "RequiredErrorMessage")]
[Display(ResourceType = typeof(DCC.Main.Resources.Resources), Name = "UserName")]
[Remote("ValidateUserNameDuplicationOperation", "User", ErrorMessageResourceType = typeof(DCC.Main.Resources.Resources), ErrorMessageResourceName = "AlreadyExistsErrorMessage", AdditionalFields = "InitialValue")]
public string UserName { get; set; }
[Required(ErrorMessageResourceType = typeof(DCC.Main.Resources.Resources), ErrorMessageResourceName = "RequiredErrorMessage")]
[Display(ResourceType = typeof(DCC.Main.Resources.Resources), Name = "Password")]
[DataType(DataType.Password)]
public string Password { get; set; }
}
Controller
public class UserController : BaseController
{
public ActionResult ValidateUserNameDuplicationOperation(string UserName, string InitialValue)
{
if (UserName == InitialValue)
return Json(true);
bool result = _TicketServiceWrapper.UserNameExists(UserName);
return Json(!result, JsonRequestBehavior.AllowGet);
}
}
View
@model DCC.UI.Web.Model.User.UserEntityViewModel
<div class="modal-content">
@using (Html.BeginForm(Model.ID.HasValue ? "Edit" : "Create", "User", FormMethod.Post, new { autocomplete = "off" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<div class="cotainer-fluid">
<div class="modal-body">
@if (Model.ID.HasValue)
{
@Html.HiddenFor(m => m.ID)
@Html.Hidden("InitialValue", Model.UserName)
}
<div class="form-group">
@Html.LabelFor(m => m.UserName)
@Html.TextBoxFor(m => m.UserName, new { @class = "form-control", value = "", autocomplete = "off" })
@Html.ValidationMessageFor(m => m.UserName)
</div>
<div class="form-group">
@Html.LabelFor(m => m.Password)
<input style="display:none" type="text" name="fakeusernameremembered" />
<input style="display:none" type="password" name="fakepasswordremembered" />
@Html.PasswordFor(m => m.Password, new { @class = "form-control", data_val = Model.ID.HasValue ? "false" : "true", value = "", autocomplete = "off" })
@if (!Model.ID.HasValue)
{
@Html.ValidationMessageFor(m => m.Password)
}
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">@Resources.Close</button>
<button id="submitNewRole" type="submit" class="btn btn-primary">@Resources.Save</button>
</div>
</div>
}
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
In the User form there is a button to open a bootstrap dialog to create a new user and I want to satisfy the uniqueness of the 'UserName' field so I add a Remote Attribute To the UserName field. In the development environment every things work fine, even I publish the website to the development environment IIS and again every things work fine,this is a snapshot of 'Create New User Dialog' and the html that the Ajax call fill into the dialog:
<div class="form-group">
<label for="UserName">User Name</label>
<input autocomplete="off" class="form-control" data-val="true" data-val-remote="This Value Already Exists." data-val-remote-additionalfields="*.UserName,*.InitialValue" data-val-remote-url="/User/ValidateUserNameDuplicationOperation" data-val-required="This Field Is Required." id="UserName" name="UserName" type="text" value="">
<span class="field-validation-valid" data-valmsg-for="UserName" data-valmsg-replace="true"></span>
</div>
So as I said every things work fine, it means for UserName field the Required,Display and Remote Attributes work fine and for the Password field the Required and Display attributes work fine.
BUT
The problem is when i publish the website to the production environment (Windows Server 2012) the Remote attribute doesn't work and even cause the other attributes for UserName not to work like the Display and Required and event the html that the ajax call get for the UserName Filed is different :
<div class="form-group">
<label for="UserName">UserName</label>
<input autocomplete="off" class="form-control valid" id="UserName" name="UserName" type="text" value="" aria-invalid="false">
<span class="field-validation-valid" data-valmsg-for="UserName" data-valmsg-replace="true"></span>
</div>
The Image for unsuccessful path
There is nothing in the developer option of browser,no errors! I even try to compare the settings of IIS in both environment but i couldn't find anything.
Its so weird to me so I start to write a question.