skip to Main Content

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

  1. uninstall all Twilio packages
  2. And re-install Twilio API helper library latest version

And the issue was fixed

Thank you

2

Answers


  1. Chosen as BEST ANSWER

    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.


  2. If RedirectToAction is not working as expected, consider moving the POST 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.

    public class AgentOpenDeal : Controller
    {
        private readonly IClientService _clientService;
    
        public AgentOpenDeal(IClientService clientService)
        {
            _clientService = clientService;
        }
    
        [HttpPost]
        [ValidateAntiForgeryToken]
        public async Task<ActionResult> ClientDeal(Models.VM.Client model, FormCollection formCollection, int CoOrdName)
        {
            await _clientService.InsertClientAsync(model, formCollection);
            await _clientService.SendMessageAsync(agentPhone, msg);
    
            TempData["SM"] = "New Lead successfully assigned!";
    
            // Return the view directly
            return View("Deal");
        }
    }
    
    

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search