PDA

View Full Version : [CLOSED] Send Json object with get value with loaders



Tactem
Oct 07, 2013, 10:09 AM
i have json object and some parameters in js function

i want to send in my controller action all of variable but json object is always null.
i use actually my get values with url

js function

var json = JSON.stringify(bandeau);
var newTab = Ext.create("Ext.container.Container", {
id: idTab,
renderTo: Ext.getBody(),
hidden: true,
layout: 'fit',
border: false,
loader: {
renderer: "frame",
url: AppPath + "DashBoardGenerator/LoadTable?tableName=" + tableName + "&idProc=" + id + "&clientId=" + clientId + "&currencyId=" + currencyId,
loadMask: {
showMask: true,
msg: TIO.Resources.PreparingDisplay
},
params:
{
bandeau: json
}

}
})


action controller

public ActionResult LoadTable(string tableName, int idProc, int clientID, int? currencyId, Headband bandeau)
{

}

use parameter value

private DashBoardExtendedParametersModel GetDashBoardExtendedParametersModelByUrl(Uri url)
{
string queryString = (!string.IsNullOrEmpty(url.Query)) ? url.Query.Remove(0, 1) : string.Empty;// supression du ?
if (!string.IsNullOrEmpty(queryString))
{
Dictionary<string, string> uriParameters = new Dictionary<string, string>();
queryString.Split('&').ToList().ForEach(p => uriParameters.Add(p.Split('=')[0], p.Split('=')[1]));

return new DashBoardExtendedParametersModel
{
ClientId = int.Parse(uriParameters["clientId"]),
CurrencyId = (uriParameters["currencyId"] != "null") ? int.Parse(uriParameters["currencyId"]) : (int?)null,
TableName = uriParameters["tableName"],
IdProc = int.Parse(uriParameters["idProc"])
};
}


return null;
}

Regards

Daniil
Oct 07, 2013, 2:47 PM
Hi @Tactem,

I am not sure, but please try to replace:

params: {
bandeau: json
}
with

params: json

Daniil
Oct 07, 2013, 3:20 PM
Please ignore my previous post.

I overlooked that you are using

renderer: "frame"

An iframe can be loaded via a GET request only. So, the only way to send the parameters is a query string. So, please pass bandeau via a query string as well if it doesn't exceed the size limitation of a GET request.

Tactem
Oct 07, 2013, 4:22 PM
thx Daniil

the good version


var idTab = "Tab" + tabIndex;
//DashBoardExtendedParametersModels[idTab] = createDashBoardExtendedParametersModel(tableName, id, clientId, currencyId);
var json = JSON.stringify(bandeau);
var newTab = Ext.create("Ext.container.Container", {
id: idTab,
renderTo: Ext.getBody(),
hidden: true,
layout: 'fit',
border: false,
loader: {

renderer: "frame",
url: AppPath + "DashBoardGenerator/LoadTable?tableName=" + tableName + "&idProc=" + id + "&clientId=" + clientId + "&currencyId=" + currencyId + "&serializedHeadBand=" + encodeURI(json),
loadMask: {
showMask: true,
msg: TIO.Resources.PreparingDisplay
}
}
})


public ActionResult LoadTable(string tableName, int idProc, int clientID, int? currencyId, string serializedHeadBand)
{
Headband headBand = null;
try
{
var json = HttpUtility.UrlDecode(serializedHeadBand);
headBand = JsonConvert.DeserializeObject<Headband>(json);
}
catch { }
}