locked
Getting error while calling RedirectToAction method RRS feed

  • Question

  • User-775001650 posted

    Hi ,

      I am facing issue while redirect to another control when session as expired.  I am using some java script method to call ActionMethod1

    1. .ajax({
    2.         type: "get",
    3.       url: "/SomeController/ActionMethod1",
    4.       data: { accountNumber: accountNumber }, dataType: 'json',
    5. success: function(response){$(target).html(response);};")
    6. error:function(response){$(target).html('An error occured');
    7. });

    I have the below ActionMethod which is having RedirectToActionMethod.

    public ActionResult ActionMethod1()

    {

       if(Session==null)

       {

          return RedirectToActionMethod("Signoff","Logout");

    }

    return PartialView();

    }

    }

    public ActionResult Signoff()

    {

       return view();

    }

    Issue :  when I redirect to Sighoff action method it is returning View but it is binging signoff view at line no: 5. which javascript function is calling initially .

    Query: How to stop the initially  javascript call if session is null .

    Thanks in advance,

    Venkat

    Tuesday, March 6, 2018 1:53 PM

Answers

  • User-284744251 posted

    Try following code

    public ActionResult ActionMethod1()
    {
       if(Session==null)
       {
          return null;
       }
    
       return PartialView();
    
    }
    

    $.ajax({
            type: "get",
          url: "/SomeController/ActionMethod1",
          data: { accountNumber: accountNumber }, dataType: 'json',
    success: function(response){
       if (response == null) 
       {
          window.location.href = '@Url.Action("Signoff")';
       } 
       else
       {
          $(target).html(response);
       }  
    }, 
    error:function(response){$(target).html('An error occured');
    }});

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 6, 2018 4:23 PM

All replies