0

what is the best way to pass model data from View to Controller using actionLink. actually my action link is download link and i want to pass report model as it contains datatable information.

   private void DownloadReport(ReportModel rptModel)
   {
       // want to recieve report model here.
     // to do so.
   }
shujaat siddiqui
  • 1,527
  • 1
  • 20
  • 41

2 Answers2

0

An ActionLink is ultimately just an anchor element.

Instead, use a form with an anchor element that submits the form.

The corresponding controller method would accept your ReportModel.

Joe Ratzer
  • 18,176
  • 3
  • 37
  • 51
0

You can use Ajax post method for the same..

For example in your view :-

<script type="text/javascript">
var rptModel = {
    val1: "val1",
    ....
};

$.ajax({
    url: '/NameOfController/DownloadReport,
    type: 'POST',
    data: JSON.stringify(rptModel),
    contentType: 'application/json; charset=utf-8',
    success: function (data.success) {
        alert(data);
    },
    error: function () {
        alert("error");
    }
});
</script>

And this whatever you pass from view you will get in your action method.

Neel
  • 11,625
  • 3
  • 43
  • 61