0

I have created my WebAPI controllers' documentation using HelpPage. I have following model in my web api.

public class InfoModel
{
    [Required]
    public int id { get; set; }

    [Required]
    public string title { get; set; }

    public string status { get; set; }

    public string created_at { get; set; }
}

HelpPage renders InfoModel on help page like this:

{
   "id": 1,
   "title": "Sample string 2",
   "status": "Sample string 3",
   "created_at": "Sample string 4"
}

Using [Required] attribute from Model Validation and I want to highlight properties having [Required] attribute. How can I customize HelpPage MVC plugin to bold "id" and "title", so that user may know that these attributes are REQUIRED:

{

"id": 1,

"title": "Sample string 2",

"status": "Sample string 3",

"created_at": "Sample string 4"

}

I understand Jquery/CSS but for that HelpPage MVC should render HTML contents with some marking for [Required] attributes so that JS/CSS may style them differently on client side. I am expecting some modifications in Areas.HelpPage.ObjectGenerator class that is responsible for generating HTML for InfoModel.

theGeekster
  • 6,081
  • 12
  • 35
  • 47
  • Apply some css? font-weight: bold; – Sam Leach Feb 17 '14 at 08:32
  • Apply CSS to what? I mean how to let CSS know to distinguish between required and optional parameters? – theGeekster Feb 17 '14 at 08:35
  • You'll have to define what parameters are required and optional. – Sam Leach Feb 17 '14 at 08:36
  • @theGeekster What Sam is saying (albeit it's quite vague) is that the HelpPages just write out a Razor view like any other in your MVC project. Have a look at the `Index.cshtml` generated in your `Areas/HelpPage` folder to see the DOM structure generated - then include any CSS you might require. As mentioned, you might need jQuery to add classes based on the text content of the API list – CodingIntrigue Feb 17 '14 at 08:38
  • I have added my sample InfoModel class code above that is annotating key parameters with [Required] attribute. This is what I want to display on HelpPage in some way to let user know that these parameters are [Required]. I understand Jquery/CSS but for that HelpPage MVC should render HTML contents with some marking for [Required] attributes so that JS/CSS may style them differently on client side. I am expecting some modifications in Areas.HelpPage.ObjectGenerator class that is responsible for generating HTML for InfoModel. – theGeekster Feb 17 '14 at 09:37

2 Answers2

0

Use jQuery to apply css to the id and title:

$('foo').css("font-weight","Bold");
Sam Leach
  • 12,746
  • 9
  • 45
  • 73
0

if you are using latest version of Web API, then you get helpful information regarding data annotation attributes like Required etc.

Example: enter image description here

Kiran
  • 56,921
  • 15
  • 176
  • 161