Search Results

Search found 2 results on 1 pages for 'onebelizean'.

Page 1/1 | 1 

  • Error messages for model validation using data annotations

    - by oneBelizean
    Given the follow classes: using System.ComponentModel.DataAnnotations; public class Book{ public Contact PrimaryContact{get; set;} public Contact SecondaryContact{get; set;} [Required(ErrorMessage="Book name is required")] public string Name{get; set;} } public class Contact{ [Required(ErrorMessage="Name is required")] public string Name{get; set;} } Is there a clean way I can give a distinct error message for each instance of Contact in Book using DataAnnotations? For example, if the name was missing from the PrimaryContact instance the error would read "primary contact name is required". My current solution is to create a validation service that checks the model state for field errors then remove said errors and add them back using the specific language I'd like.

    Read the article

  • Why is the base class being called?

    - by oneBelizean
    I'm new to c# so bare with me. But here's my situation. interface Icontainer{ string name(); } abstract class fuzzyContainer : Icontainer{ string name(){ return "Fuzzy Container"; } } class specialContainer: fuzzyContainer{ string name(){ return base.name() + " Special Container"; } } Icontainer cont = new SpecialContainer(); cont.name(); // I expected "Fuzzy Container Special Container" as the output. When I run my code as described above the output is simply "Fuzzy Container". What am i missing here? Is there a better way to get the desired results?

    Read the article

1