Cicciux
Cicciux

Reputation: 179

Pass parameter to jQuery load dialog in .net

i have this jquery function, it load a dialog and call the action in controller, but in controller don't arrive the value parameters (val)..

The action is called correctly because open the dialog e load the data in viewmodel.

I have create a object for pass the data (ActivityParameterVO actPar)

public class ActivityParameterVO
{
public decimal EOA_EVEOPTID { get; set; }
public decimal EOA_ACTID { get; set; }

......

}

This is the jquery function

parameters = function (EVEOPTID, ACTID) {

var val = {
'EOA_EVEOPTID' : EVEOPTID,
'EOA_ACTID' : ACTID
};

$("#dialog").dialog({

autoOpen: true, modal: true, height: 800, width: 1000, resizable: false,
open: function () {
console.log(JSON.stringify(val));
$.ajax({
type: 'POST',
data: JSON.stringify(val),
url: '/Event/LoadParameters',
contentType: "application/json"
}).done(function (res) {
$("#dialog").html(res);
$('#dialog').dialog('open');
});
},
position: {
my: 'top', at: 'top'
},
buttons: [
{
html: "Cancel",
"class": "btn btn-default",
click: function () {
$(this).dialog("close");
}
},
{
html: "<i class='fa fa-check'></i>&nbsp; OK",
"class": "btn btn-primary",
click: function () {
$(this).dialog("close");
}
}
]
})
};

The Action Metod

public IActionResult LoadParameters([FromBody] ActivityParameterVO actPar)
{
EventActivityParametersViewModel eventActivityParameters = this.eventStructureBLL.GetParameters("ITA", actPar1);


return PartialView("~/Views/Event/Parameters.cshtml", eventActivityParameters);
}

Upvotes: 0

Views: 178

Answers (1)

Cicciux
Cicciux

Reputation: 179

I had simply forgotten to mark with [httpPost] tha action method

**[httpPost]**
public IActionResult LoadParameters([FromBody] ActivityParameterVO actPar)
{
EventActivityParametersViewModel eventActivityParameters = this.eventStructureBLL.GetParameters("ITA", actPar);


return PartialView("~/Views/Event/Parameters.cshtml", eventActivityParameters);
}

Now it works

Upvotes: 2

Related Questions