0

I have the following button:

<a id="commons" href="#" onclick="$('#sideViewAside').load('@Url.Action("PurchaseOrderSideView")', {orderId: '@item.OrderId'});" data-ma-action="sidebar-open" data-ma-target="#detailsTab" class="hidden-xs ma-trigger btn btn-icon command-edit waves-effect waves-circle"><span class="zmdi zmdi-view-list"></span></a> 

My Controller has both the GET and POST method. When I run the code, on clicking this button, the POST method is being called, whereas, I want the GET method to be called. What am I doing wrong here?

Dashamlav
  • 225
  • 4
  • 17
  • 3
    You're including data. That triggers a POST. If you want a GET, you need to use the query string parameters. – Heretic Monkey Jul 11 '18 at 20:44
  • Oh. But I need to pass `orderId` to my `GET` method as it is the input parameter for my `GET` method. How to add that? – Dashamlav Jul 11 '18 at 20:48
  • 1
    If you want a GET, you need to use the query string parameters. I believe there's an overload of `Url.Action()` that lets add parameters, as in this question: [Url.Action parameters?](https://stackoverflow.com/q/6278694) – Heretic Monkey Jul 11 '18 at 20:51

1 Answers1

1

For this code sending request with Post, it is caused by that you pass object to .load function. For .load, its default method is Get, but it will use Post if you use with object.

The POST method is used if data is provided as an object; otherwise, GET is assumed.

You could try code below to use Get with orderId as input.

<a id="commons" href="#" 
  onclick="$('#sideViewAside')
  .load('@Url.Action("PurchaseOrderSideView",
  new {orderId = "111"})')" data-ma-action="sidebar-open" data-matarget="#detailsTab"
class="hidden-xs ma-trigger btn btn-icon command-edit waves-effect waves-circle">
<span class="zmdi zmdi-view-list">Test1</span>

Edward
  • 28,296
  • 11
  • 76
  • 121