skip to Main Content

I have a link. Its triggers my ajax. I want to open a new page after this triger.
But it’s returning back to my ajax after the trigger. There is my code.

HTML

<a onclick="SiparisYazdir(@item.id)" >Print</a>

ajax

function SiparisYazdir(id)
    {
      $.ajax({
          url: '/Order/Print',
          type: 'GET',
          data: { "value": value, 'id': id } // value is taking from another method.
      });        
    }

controller

public IActionResult Print(int value, int id)
        {
            //taking model here
            return View(model);
        }

2

Answers


  1. return View(model) will return the html content of your view
    you cant put this html into your desired tag

    function SiparisYazdir(id)
        {
          $.ajax({
              url: '/Order/Print',
              type: 'GET',
              data: { "value": value, 'id': id } // value is taking from another method.,
              success:(result)=>{
                 $('your_desire_elemnt').html(result)
              }
          });        
        }
    
    
    Login or Signup to reply.
  2. If you want to redirect to another page, I think there is no need ajax here

    function SiparisYazdir(id) {
        window.location.href = "/Home/Privacy?value=" + value + "&id=" + id;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search