Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Gents,

I have a dropdownlist which will pass the data to the query string and its working fine. I have another dropdownlist that i want to pass the value to the query string in url along with the previous dropdown, how can i do that in asp.net mvc

your help is much appreciated and save my hours.

Regards
Posted
Comments
ZurdoDev 19-Feb-13 16:09pm    
If you have code that does one dropdownlist into the query string what's the issue getting the 2nd one to be there as well?
Zoltán Zörgő 19-Feb-13 16:12pm    
It looks quite simple, so please paste here the relevant portion of the view.
Ahamed Azeem 19-Feb-13 16:35pm    
Dear Ryan,

That is the issue, when I select a dropdown, the url query string is replaced by the other value,

for ex
http://localhost:7919/Contract/Create?OccupationId=f73536b5-f18c-470c-b921-f542e5b39962

or

http://localhost:7919/Contract/Create?NationalityId=fb92cf56-716b-414a-99f6-c97ad440a8db

Either any one of the above value is coming not both. I want the url to keep the value and append the other one

regards
Ahamed Azeem 19-Feb-13 16:15pm    
Dear Ryan,

That is the issue, when I select a dropdown, the url query string is replaced by the other value,

for ex
http://localhost:7919/Contract/Create?OccupationId=f73536b5-f18c-470c-b921-f542e5b39962

or

http://localhost:7919/Contract/Create?NationalityId=fb92cf56-716b-414a-99f6-c97ad440a8db

Either any one of the above value is coming not both. I want the url to keep the value and append the other one

regards
[no name] 19-Feb-13 16:44pm    
How can anyone tell what it is that you are doing wrong unless you post the code?

HTML
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
 $(function() {
     var collectParams = function(){
		var params = { OccupationId:$("#Occupation").val(), NationalityId:$("#Nationality").val() };
		if(params.OccupationId && params.NationalityId)
		{
			location.href=@Html.Action("Create","Contact") + "?" + jQuery.param(params)
		}
	 };
	 
	 $("#Nationality").change(collectParams);
	 $("#Occupation").change(collectParams);
    });
</script>
@Html.DropDownList("NationalityId", ViewBag.NationalityId as SelectList, String.Empty, new { id="Nationality" })
@Html.DropDownList("OccupationId", ViewBag.OccupationId as SelectList, String.Empty, new { id="Occupation" })

OnChange is called for both dropdowns, but it is triggering relocation only if both are specified.
 
Share this answer
 
v3
Comments
Ahamed Azeem 19-Feb-13 16:51pm    
Dear Zoltan,

I have posted my view details in the previous comment, pls check and suggest
Zoltán Zörgő 19-Feb-13 16:53pm    
I would not use onchange, since than you can change only one of them. Put this logic on javascript side as suggested. Do you want to refresh the same view with different parameters or is the /Contract/Create an other one?
Ahamed Azeem 19-Feb-13 17:01pm    
actually i am brining another data from the database using nationality id and occupation id, that data will automatically get filled in the textbox once both of these values selected
Zoltán Zörgő 19-Feb-13 17:25pm    
See update
Ahamed Azeem 24-Feb-13 1:11am    
It shows below exception

"The controller for path '/Contract/Create' was not found or does not implement IController."}
[removed, duplicated by the system, but I can't delete it]
 
Share this answer
 
v3

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