Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8836125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:25:10+00:00 2026-06-14T09:25:10+00:00

I have a model [Validator(typeof(ContractValidator))] [Route(/contracts, POST)] public class Contract { public int ContractID{get;

  • 0

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
.
.
.

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T09:25:11+00:00Added an answer on June 14, 2026 at 9:25 am

    I’ve just committed a fix for this so you should no longer get this error with the next version of ServiceStack in HEAD now (or at the end of this week on NuGet).

    The new behaviour is any Exception will populate the ModelError property on the Razor View. The @Model will be null, but you can access the typed errors by looking at the base.ResponseStatus property on the View Page.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have model: [Validator(typeof(RegisterValidator))] public class RegisterModel { public string Name { get; set;
I have an MVC3 view model defined as: [Validator(typeof(AccountsValidator))] public class AccountViewModel { public
I have Entity set and i create partial class [Bind(Include = ID,Note,Spec,Retired)] [MetadataType(typeof(SomeClass))] public
I have a Model similar to the following public class TaskModel { public int
I have a model class that uses a custom validator as shown in following
The scenario Suppose I have the following two model classes: public class ProductColor {
Let's say I have a user class setup with validation like this: [MetadataType(typeof(ssUserMetaData))] public
Imagine you have two fields in your Model: public class MyModel { [Required(ErrorMessageResourceType =
I have a model defined this way class Lga < ActiveRecord::Base validates_uniqueness_of :code validates_presence_of
I have a model: review.rb class Review < ActiveRecord::Base validates :title, :presence => true

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.