Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello,

I have a requirement to pass comma separate string as a parameter from View to another Controller.

Ex:

I have parameter in /Home/findaContractor View and want to pass /Postwork/Create Controller

Currently, I am passing parameters like below:

str='1,2,3,4,5';
window.location.href = "/PostWork/Create?Contrators=" + str;


str='1,2,3,4,5' is string of Id (it may be more Ids in str).

Currently, I am passing in querystring, but how can I pass instead Querystring? so it should not display in querystring and I also get string parameter on another controller.

Thanks

What I have tried:

Currently, I am passing parameters like below:

str='1,2,3,4,5';
window.location.href = "/PostWork/Create?Contrators=" + str;
Posted
Updated 24-Mar-17 4:57am
v2
Comments
Karthik_Mahalingam 24-Mar-17 6:40am    
ok,what is the issue?
kkakadiya 24-Mar-17 7:09am    
Currently, I am passing in querystring, but how can I pass instead Querystring? so it should not display in querystring and I also get string parameter on another controller.
Karthik_Mahalingam 24-Mar-17 7:16am    
then how will you pass the data? what is the issue in query string?
kkakadiya 24-Mar-17 7:20am    
Querystring displays all the values on URL and it is not good that we pass long value in querystring. someone can change value.
exa.
http://localhost:25649/PostWork/Create?Contrators=5,6,18,20096,74,84,89,10082,86,10089,20092,20106
Karthik_Mahalingam 24-Mar-17 7:30am    
from where you will call this ?
and what it will return ?

str='1,2,3,4,5';
window.location.href = "/PostWork/Create?Contrators=" + encodeURIComponent(str);
 
Share this answer
 
If you don't want the values to appear in the querystring, then you need to make a POST request:
JavaScript
var form = document.createElement("form");
form.setAttribute("method", "POST");
form.setAttribute("action", "/PostWork/Create");

var contractors = document.createElement("input");
contractors.setAttribute("type", "hidden");
contractors.setAttribute("name", "Contractors");
contractors.setAttribute("value", str);

form.appendChild(contractors);
document.body.appendChild(form);
form.submit();

Your action will obviously need to accept POST requests as well as GET requests. If you haven't added an [HttpGet] attribute to the action, it should just work.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900