3

I have a property on my viewmodel of type int?

/// <summary>
/// Represents A company Id 
/// </summary>
[Range(1, 999999999, ErrorMessage="Error"])          
public int? CompanyId{ get; set; }

From the textbox I user enter a big number that overflows int32 maxValue, then I think an internal validation exception is thrown but the message doesn't appear.

I am overriding default messages in global.asax by calling:

DefaultModelBinder.ResourceClassKey = "GlobalResources";

Do you know what key I should enter to override resources so that the message will appear? Is there any specific message for Int32 overflow?

I've overridden the PropertyValueInvalid but it doesn't show. It seems like there is another key that need to be overridden. Please point me where can I find all list of default keys.

7
  • Do you want to show the message on your View? If so, can you post the code for the View? Commented Dec 18, 2012 at 18:06
  • I cant now since I am not near pc , but I have @Html.ValidationSummary() inside BeginForm if this was the question. Commented Dec 18, 2012 at 18:12
  • Do you also have a @Html.ValidationMessageFor(model => model.CompanyId) on your View? Commented Dec 18, 2012 at 18:13
  • No , only Validation summary Commented Dec 18, 2012 at 18:16
  • Without it, a validation message for that particular property won't show up. However, the summary should still show up. Is that the case? Commented Dec 18, 2012 at 18:17

1 Answer 1

1

You need to add @Html.ValidationMessageFor(model => model.CompanyId) to your view so the validation message actually shows. Otherwise you will only get a red border on your textbox, as you mentioned.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.