Dashamlav
Dashamlav

Reputation: 245

How can I make the following button call the GET method and not the POST method?

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?

Upvotes: 0

Views: 207

Answers (1)

Edward
Edward

Reputation: 29996

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>

Upvotes: 1

Related Questions