I'm working on an asp.net mvc application that needs to pass parameters to an action. I'm passing the parameter through the url. The action is called but the parameter value is broken. Example, if I have a string "This is the example of a string passed by parameter", when it arrives in the action it arrives like "This is the", ie it takes only a part.
I don't know if this is due to the fact that this string is in json format and some character may be causing this information break. In the analysis I noticed that when there is a "#" the string is broken and only what is on the left is passed. I tried replacing the "#" with the "$" using replace, but that didn't work. The string that arrives from the other side is different from the original that was generated by javascript.
async function GravarPlayList() {
var listaDeVideos = [];
for (var i = 0; i < listaDeIds.length; i++) {
var videos = await executeSearch(listaDeIds[i], maxResult);
for (var j = 0; j < videos.length; j++) {
listaDeVideos.push(videos[j]);
}
}
var jsonVideos = JSON.stringify(listaDeVideos);
var url = "/Playlist/CreatePlaylist?pListaIds=" + jsonVideos;
var novaUrl = url.replace('#', '$');
window.location.href = novaUrl;
}
[HttpGet]
public ActionResult CreatePlaylist(string pListaIds)
{
var pcustom = pListaIds.Replace('$', '#');
AppCache.Instance.VideoPesquisa = JsonConvert.DeserializeObject<IEnumerable<VideoItem>>(pcustom);
PlaylistModel playlistModel = new PlaylistModel() { VideosPesquisa = AppCache.Instance.VideoPesquisa };
return View(playlistModel);
}
example of a string passed by parameter
[
{
"kind":"youtube#playlistItem",
"etag":"vINbNEDWl2kOPwB7uZNfjznpqic",
"id":"UExCbG5LNmZFeXFSZ2daWmdZcFBNVXhkWTFDWWtadEFSUi41NkI0NEY2RDEwNTU3Q0M2",
"snippet":{
"publishedAt":"2018-06-24T07:24:38Z",
"channelId":"UCQYMhOMi_Cdj1CEAU-fv80A",
"title":"C Programming – Features & The First C Program",
"description":"Programming & Data Structures: C Programming – Features & The First C Program\\nTopics discussed:\\n1. Features of C programming.\\n2. High-level language Vs Low-level language.\\n3. Explanation of a…vi/Wslbb1UQUSc/hqdefault.jpg",
"width":480,
"height":360
},
"standard":{
"url":"https://i.ytimg.com/vi/Wslbb1UQUSc/sddefault.jpg",
"width":640,
"height":480
},
"maxres":{
"url":"https://i.ytimg.com/vi/Wslbb1UQUSc/maxresdefault.jpg",
"width":1280,
"height":720
}
},
"channelTitle":"Neso Academy",
"playlistId":"PLBlnK6fEyqRggZZgYpPMUxdY1CYkZtARR",
"position":168,
"resourceId":{
"kind":"youtube#video",
"videoId":"Wslbb1UQUSc"
},
"videoOwnerChannelTitle":"Neso Academy",
"videoOwnerChannelId":"UCQYMhOMi_Cdj1CEAU-fv80A"
}
}
]
string when it arrives in action
[{"kind":"youtube"
How can I solve this? I don't want to use ajax as I need to redirect to another page.