Here is my scenario - on the page, there will be a button, on the button click there will be a popup and the user will enter some detail. On submit button, I need to create a contact and save custom facets on xDB and after that, there will be a confirmation message on the same popup.
Because I do not want to post back the page, I am doing an ajax call, and Tracker
will not be available on ServicesApiController
. Is there any solution to this?
Code:
public class SubscriptionApiController : ServicesApiController
{
private readonly IContactRepository _contactRepository;
public SubscriptionApiController()
{
_contactRepository = ServiceLocator.ServiceProvider.GetService<IContactRepository>();
}
[HttpPost]
public HttpResponseMessage Post(SubscriptonModel model)
{
try
{
}
catch (Exception ex)
{
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, Constants.ErrorMessage.InternalServerError);
}
}
}
Route
public class WebApiServices
{
public void Process(PipelineArgs args)
{
GlobalConfiguration.Configure(Configure);
}
protected void Configure(HttpConfiguration configuration)
{
var routes = configuration.Routes;
routes.MapHttpRoute("subscriptionApi", "api/{controller}/{action}", new { });
}
}