Passing parameter to controller

Passing parameter to controller

alesk4alesk4 Posts: 2Questions: 1Answers: 0

Hello
I have web app mvc and using jquery datatables. I have a view which shows detail of some entity and i want to show data from another table paired with Id key in datatable.

In this view there is datatable with:

serverSide": true,
 "ajax": {
     "url": "Contracts/LoadContractNotes",
     "type": "POST",
     "datatype": "json",
     "data": function (data) {
         data.test = $('#test').val();
     }
         
 }

Value for "test" should be here

<input id="test" type="hidden" name="ContractId" value="@ViewBag.ContractId" />

In controller i use:

[HttpPost]
public IActionResult LoadContractNotes(){

.....
.....

}

I tried many thing to pass parameter "test" to LoadContractNotes so i would be able to use it for filtering data.

Could you please give me advice?

Thank you
A

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,441Questions: 1Answers: 10,459 Site admin
    Answer ✓

    If you have a look in the request parameters for the Ajax request in your browser's network inspector, you should be able to see the test parameter being submitted. Is that the case? If so, you should then be able to use Request.Form["test"] or similar to access the property. For the server-side of things, you'd need to refer to Microsoft's .NET documentation for more details.

    Allan

  • alesk4alesk4 Posts: 2Questions: 1Answers: 0

    Hello Allan.
    Thank you for aswer. Now it is working. :)

Sign In or Register to comment.