Vivek
Vivek

Reputation: 641

workaround for "Remote" attribute

I have a Register and login page both using unobtrusive ajax.
The Username property in my model is decorated with Remote("ActionName","ControllerName")
Its working fine in the Registration Page but the problem is the validation is also working in the Login Page. So how can i disable the Remote validation attribute on the Login Page but i do want the ajax functionality of signIn in the Login Page so i cant remove the unobtrusive javascript file

Upvotes: 2

Views: 178

Answers (1)

nemesv
nemesv

Reputation: 139758

You cannot turn off Remote validators dynamicly.

The solution is to not use the same model for the two view.

Instead of create two viewmodels one for login and on for the register view and annotate them differently:

public class RegisterUserViewModel
{
    [Remote("ActionName","ControllerName")]
    public string Username { get; set; }

    //...
}

public class LoginUserViewModel
{
    public string Username { get; set; }

    //...
}

For mapping properties from your viewmodel to your models in the controller you can use some object-object mapper like AutoMapper

Upvotes: 1

Related Questions