Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 20, 2012 01:36 PM by bruce (sqlwork.com)
Member
39 Points
24 Posts
Feb 17, 2012 01:08 PM|LINK
In the View: Home/Index.cshtml
<select name="select-choice-0" id="select-choice-1"> <option value="option1">Option1</option> <option value="option2">Option2</option> <option value="option3">Option3</option> </select> <button name="getit" type="button" id="getit">Populate the picklist</button> <select name="select-choice-0" id="select-choice-2"> //Populate the value here. </select>
When the button clicks (getit), I want to pass the selected value (option1-3) to a controller, and within the controller, I have :
{ if(option1) return collection1; if(option2) return collection2; if(option3) return collection3; }
each collection includes some string values , i.e. collection1 include collection1-1, collection1-2, collection1-3.
then in the Index View, it should has:
<select name="select-choice-0" id="select-choice-2"> //Populate the value here. <option value="collection1-1">collection1-1</option> <option value="collection1-2">collection1-2</option> <option value="collection1-3">collection1-3</option> </select>
Also the selection box should be populated without reloading the page, so AJAX.
All-Star
24675 Points
4250 Posts
Feb 17, 2012 01:15 PM|LINK
Have a look here
Feb 17, 2012 02:12 PM|LINK
Thanks Raduenuca, this is a great post, however it doesn't quite answer my question.
134822 Points
21599 Posts
Moderator
MVP
Feb 17, 2012 02:24 PM|LINK
ceo_uk When the button clicks (getit), I want to pass the selected value (option1-3) to a controlle
PLease see http://bit.ly/mvc_ajax_jquery
Feb 17, 2012 03:37 PM|LINK
?? The link bring me to 404?
Feb 17, 2012 08:27 PM|LINK
Any updates?
Feb 18, 2012 01:34 AM|LINK
ceo_uk ?? The link bring me to 404?
You are the first one! try http://msprogrammer.serviciipeweb.ro/2011/12/05/jquery-ajax-request-and-mvcdetailed/
Feb 20, 2012 08:48 AM|LINK
Thanks ignatandrei,
Does my requirement have to use the PartialViews in order to popup the picklist with return values?
This is important because I try to put all code in a singnle View/Controller, is that possible?
Feb 20, 2012 08:52 AM|LINK
you can use a partial view, return data via json ...no limit.
ceo_uk This is important because I try to put all code in a singnle View/Controller, is that possible?
see mvc4 beta, single page application
Feb 20, 2012 08:59 AM|LINK
Thanks ignatandrei, I'm using the MVC4 beta, so maybe the Single Page application is something I'm looking for.
Does anyone has an example about MVC4 single page application in my question?
ceo_uk
Member
39 Points
24 Posts
How to populate a selection box with a button click event on the same view?
Feb 17, 2012 01:08 PM|LINK
In the View: Home/Index.cshtml
When the button clicks (getit), I want to pass the selected value (option1-3) to a controller, and within the controller, I have :
{
if(option1) return collection1;
if(option2) return collection2;
if(option3) return collection3;
}
each collection includes some string values , i.e. collection1 include collection1-1, collection1-2, collection1-3.
then in the Index View, it should has:
<select name="select-choice-0" id="select-choice-2">
//Populate the value here.
<option value="collection1-1">collection1-1</option>
<option value="collection1-2">collection1-2</option>
<option value="collection1-3">collection1-3</option>
</select>
Also the selection box should be populated without reloading the page, so AJAX.
raduenuca
All-Star
24675 Points
4250 Posts
Re: How to populate a selection box with a button click event on the same view?
Feb 17, 2012 01:15 PM|LINK
Have a look here
Radu Enuca | Blog
ceo_uk
Member
39 Points
24 Posts
Re: How to populate a selection box with a button click event on the same view?
Feb 17, 2012 02:12 PM|LINK
Thanks Raduenuca, this is a great post, however it doesn't quite answer my question.
ignatandrei
All-Star
134822 Points
21599 Posts
Moderator
MVP
Re: How to populate a selection box with a button click event on the same view?
Feb 17, 2012 02:24 PM|LINK
PLease see http://bit.ly/mvc_ajax_jquery
ceo_uk
Member
39 Points
24 Posts
Re: How to populate a selection box with a button click event on the same view?
Feb 17, 2012 03:37 PM|LINK
?? The link bring me to 404?
ceo_uk
Member
39 Points
24 Posts
Re: How to populate a selection box with a button click event on the same view?
Feb 17, 2012 08:27 PM|LINK
Any updates?
ignatandrei
All-Star
134822 Points
21599 Posts
Moderator
MVP
Re: How to populate a selection box with a button click event on the same view?
Feb 18, 2012 01:34 AM|LINK
You are the first one! try http://msprogrammer.serviciipeweb.ro/2011/12/05/jquery-ajax-request-and-mvcdetailed/
ceo_uk
Member
39 Points
24 Posts
Re: How to populate a selection box with a button click event on the same view?
Feb 20, 2012 08:48 AM|LINK
Thanks ignatandrei,
Does my requirement have to use the PartialViews in order to popup the picklist with return values?
This is important because I try to put all code in a singnle View/Controller, is that possible?
ignatandrei
All-Star
134822 Points
21599 Posts
Moderator
MVP
Re: How to populate a selection box with a button click event on the same view?
Feb 20, 2012 08:52 AM|LINK
you can use a partial view, return data via json ...no limit.
see mvc4 beta, single page application
ceo_uk
Member
39 Points
24 Posts
Re: How to populate a selection box with a button click event on the same view?
Feb 20, 2012 08:59 AM|LINK
Thanks ignatandrei, I'm using the MVC4 beta, so maybe the Single Page application is something I'm looking for.
Does anyone has an example about MVC4 single page application in my question?