2

enter image description here

I've read here about additional information of web API help page. The data annotation actually provides the additional information for documentation. But I want to know that is there anyway to provide additional information without data annotations?

If yes then how?

If not then is there anyway to override the additional information with data annotations for instance the

[Required]

shows Required written in additional information but what if I want to show "This field is required" or something like that?

Thanks

EDIT see in picture I want to update that additional information without data annotation if possible.

1

3 Answers 3

3

So the annotation allows you to further specify requirements, i.e if you have the following model:

public class MyModel {

    [Required(ErrorMessage = "You seriously need a name here bro")]
    public string Name{ get; set; }

}

You can then automatically have the validation message shown in your ASP.Net page like so:

@model string
@Html.TextBoxFor(m => m)
@Html.ValidationMessageFor(model => model, "", new { @class = "text-danger"})

So basically, you add a field for the validation message that will be populated by ASP.Net when the Required attribute kicks in.

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

5 Comments

alright that provides an answer for overriding the message ... is there anyway for doing so without data annotation?
Yes, you can use ModelState.AddModelError() in your code and avoid data annotation - don't forget to tag the answer if it solved your problem :)
correct me if im mistaken .... im asking about Api help documentation i think this is for simple view and i dont need that
Tricky - if you want API documentation, why not use the standard constructs for doing that, i.e. by commenting using /// above methods, and then extracting your API documentation as outlined in this answer: stackoverflow.com/questions/641364/…
yes that <summary></summary> provides only the description for that property... what i need to do is provide custom additional information for properties. :( or how can i modify that to give additional information??
3

You can edit the Required Attribute in the ModelDescriptionGenerator.cs
Areas>HelpPage>ModelDescriptions>ModelDescriptionGenerator.cs
For example:

    [Required(ErrorMessage ="Must pass")]
    public string Name { get; set; }

I got: Additional information : Must pass

replace:

 { typeof(RequiredAttribute), a => "Required" }

with:

{ typeof(RequiredAttribute), a => {
            RequiredAttribute b =(RequiredAttribute)a;
            return (b.ErrorMessage);
        }

see

1 Comment

Yes. :( But u can edit the parameters.cshtml And edit the message. foreach (var annotation in parameter.Annotations) {<p>@annotation.Documentation</p>}
2

If you want to give custom additional information(using data annotation) then @Pedro G. Dias's answer is your solution but if you want to give additional information without using data annotation then I am afraid that it is not possible OR you have to use some alternative procedure to do so as commented by @DynamicVariable on your question.

PS. I've debugged documentation project to check and I found that addition information is actually provided by data annotations.

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.