I have written a code which first performs an action to insert new Object into the Table and post that I have a code from Twillio which sends a msg to WhatsApp. The complete code is working fine, only the last call where I want to return url to another page stays like LOADING and fails to return the target page.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult ClientDeal(Models.VM.Client model, FormCollection formCollection, int CoOrdName)
{
using (Db db = new Db())
{
//This works good
}
var accountSid = "AC811e03512598d0fb1588a948d8c0af95";
var authToken = "4aba7186a0637735c0a42718485f1c71";
TwilioClient.Init(accountSid, authToken);
var messageOptions = new CreateMessageOptions(
new PhoneNumber($"whatsapp:{agentPhone}"));
messageOptions.From = new PhoneNumber("whatsapp:+14155238886");
messageOptions.Body = msg;
var message = MessageResource.Create(messageOptions);
TempData["SM"] = "New Lead successfuly assigned!";
return RedirectToAction("AgentOpenDeal","Deal");
}
Any suggestions?
I have been able to resolve this by the following steps
- uninstall all Twilio packages
- And re-install Twilio API helper library latest version
And the issue was fixed
Thank you
2
Answers
The issue was with the .NET Framework, as it was not in sync with Twilio version. I had to re-install the Twilio NuGet package, and then the issue was resolved.
If
RedirectToAction
is not working as expected, consider moving thePOST
action to the controller that you want to return to. By doing this, you ensure that the action and the view are handled within the same controller, which can help resolve issues with redirection.To improve code organization and reusability, consider moving the logic to a service. This way, you can reuse the code in different parts of the application and keep the controller cleaner.