I have abstract model which has property that will be validated. I want to set current controller for controller parameter.So,I added my custom attribute which inherits from Remote attribute. The problem is validate attribute applies once when model binds.
[SimpleListRemoteValidation("ValidateName", HttpMethod = "POST", AdditionalFields = "Id,SimpleModelType")]
public string Name { get; set; }
SimpleListRemoteValidation is inherited from Remote attribute
public class SimpleListRemoteValidationAttribute:System.Web.Mvc.RemoteAttribute
{
public SimpleListRemoteValidationAttribute(string action)
: base(action, HttpContext.Current.Request.RequestContext.RouteData.Values["controller"].ToString())
{
}
}
There is model binds
@foreach (var p in Model.GetProperties())
{
<td>
@Html.Editor(p.Name)
@Html.ValidationMessage(p.Name)
</td>
}
On the first request it puts in attribute's constructor.If I go to another controller it doesn't happen.