Servicestack validation

62 views
Skip to first unread message

Ermias

unread,
Nov 10, 2012, 12:53:12 AM11/10/12
to servic...@googlegroups.com
I have a model

[Validator(typeof(ContractValidator))]
[Route("/contracts", "POST")]
public class Contract
{
public int ContractID{get; set;}
public string ContractNumber{get;set;}
}

I also have a validation class for the model above.

 public class ContractValidator : AbstractValidator<Contract>
    {
        public ContractValidator()
        {
            RuleFor(x => x.ContractNumber).Length(0, 10);
        }
    }

I also have a class to map a 'GET' request:

[Route("/contracts/{ContractID}", "GET")]
public class GetContract
  {
     public int ContractID { get; set; }
  }

...and a service:


public class ContractService : ServiceStack.ServiceInterface.Service
{
public object Get(GetContract request)
        {
            IContractRepository repository = new ContractRepository();

            return repository.GetById(request.ContractID);
            
        }

public object Post(Contract request)
        {
            IContractRepository repository = new ContractRepository();
            repository.Save(request);
            //return request; 
        }

}

Now in my Razor view to edit a contract object I have

@inherits ViewPage<Contract>
.
.
.

But the problem is I'm getting the following error when I try to save and there is a model validation error:

Unable to cast object of type 'ServiceStack.ServiceInterface.ServiceModel.ErrorResponse' to type 'DTO.Contract'

Can someone please let me know how to handle this?

Thanks,

Ermias.
Reply all
Reply to author
Forward
0 new messages