Doug Robinson Doug Robinson - 1 month ago 6 Question

VB Web API - Property Name for a Form encoded values with period in name

What should I name a property that is going to be assigned via form-encoded input from an HTTP request, to ensure that the property will be filled in when I create a new instance of the class from form-encoded input that will have some keys that have periods in the name?

I have a VB.NET application that makes use of the ASP.NET self-hosed Web API.

One of the methods accepts input from an application, Bomgar.

The data that's sent in is in a form encoded format, and looks like the following:


I'm able to process the 'request_id', 'response_url', and 'ticket_id' portions, by establishing an object that has properties with the same names.

I've done this, because I've read that when accepting this form input and sending the body of the http message containing this data into an object, it will automatically map the form input into properties containing those names.

So I have a class named Ticket, defined as below:

Public Class Ticket
Public Property response_url As String
Public Property request_id As String
Public Property ticket_id As String

End Class

And I map the content of the form data into an instance of this class via the following within my controller:

Public Sub PostProduct(<FromBody()> NewTicketRequest As Ticket)


End Sub

This correctly assigns the request_id , response_url, and ticket_id properties in that object.

However, I'd like to also capture the jump_item inputs that are being sent, and the user inputs, but I can't include a period in a property name.

How can I include properties in the Ticket class that will be filled in automatically when I pass the HTTP form-encoded data above into a new instance of that object? I'm not sure how to name them, or if I need to somehow set up another object for it.

I'd like to be able to address the user email address in a fashion similar to:




Even though the item coming in will have a period after the word user.


You can add complex properties to your Ticket model. The name of those properties should match the prefix before '.' and the type of those properties should contains properties with name after '.'.

For example to get jump_item.* values, your Ticket model should contain a property with name jump_item which is of a type that contains properties with * names: comments, computer_name, group, private_ip, public_ip, tag and type.


In below example I added a Model, Controller and a View to the default ASP.NET WebAPI project which I created using Visual Studio.


Public Class Ticket
    Public Property Id As Integer
    Public Property Text As Integer
    Public Property User As ApplicationUser
End Class

Public Class ApplicationUser
    Public Property Id As Integer
    Public Property UserName As String
    Public Property DisplayName As String
End Class


Public Class ValuesController
    Inherits ApiController

    ' POST api/values
    Public Sub PostValue(<FromBody()> ByVal value As Ticket)

    End Sub
End Class


<form action="/api/values" method="post">
    <input type="text" name="Id" />
    <input type="text" name="Text" />
    <input type="text" name="User.Id" />
    <input type="text" name="User.UserName" />
    <input type="text" name="User.DisplayName" />
    <input type="submit" value="Save" />