I am passing information from my form to my WebMethod. The goal is to populate the UseInfo object with the data from the form and also populate some properties I have added on the NewUser class which are also passed from the ajax request.
When I have as an input parameter the UserInfo, the object populates successfully after the ajax post. However, if I have the NewUser object, only the property Relationship gets populated but the UserInfo object appears as Nothing.
Any ideas what I'm doing wrong? Do I need to give a different structure to my class NewUser?
NewUser class
Public Class NewUser
Public Property UserInfo As UserInfo
Get
Return _UserInfo
End Get
Set(value As UserInfo)
_UserInfo = value
End Set
End Property
Private _UserInfo As UserInfo
Public Property Relationship As String
Get
Return m_Relationship
End Get
Set(value As String)
m_Relationship = value
End Set
End Property
Private m_Relationship As String
End Class
WebMethod
<HttpPost>
<ValidateAntiForgeryToken>
<DnnModuleAuthorize(AccessLevel:=SecurityAccessLevel.View)>
Public Function AddUserDependant(<FromBody> oNewUser As NewUser) As HttpResponseMessage
Try
If Me.UserInfo.IsInRole("Carer") Then
UsersControllerOmni.CreateDnnUser(oNewUser.UserInfo)
Return Request.CreateResponse(HttpStatusCode.OK)
Else
Return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "")
End If
Catch ex As Exception
Return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex)
End Try
End Function
AJAX
$.ajax({
type: "POST",
cache: false,
url: serviceUrl + "/ModuleTask/AddUserDependant",
beforeSend: sf.setModuleHeaders,
contentType: "application/json; charset=utf-8",
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
data: $("form").serialize()
}).done(function (result) {
}).fail(function (xhr, result, status) {
alert(result);
});