0

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.

AndreyDG
  • 25
  • 4
  • IIRC, attribute constructors are cached, have you tried doing a rebuild, then going in reverse order to see if it is just the first hit on the constructor that is being cached? – Slicksim Sep 25 '13 at 08:52
  • yes,after rebuild I get it.Where is place where I can manage this cache? – AndreyDG Sep 25 '13 at 09:13
  • tbh, i'm not sure you can, i've certainly not seen any where that it can be altered or controlled. – Slicksim Sep 25 '13 at 09:30
  • It seems @Html.Editor() save its state.So, it's necessary to refresh this "state". – AndreyDG Sep 25 '13 at 09:38

0 Answers0