to get value of selected option from dropdownlist and pass it to controllerhttp://forums.asp.net/t/1783013.aspx/1?to+get+value+of+selected+option+from+dropdownlist+and+pass+it+to+controllerWed, 21 Mar 2012 10:34:18 -040017830134890704http://forums.asp.net/p/1783013/4890704.aspx/1?to+get+value+of+selected+option+from+dropdownlist+and+pass+it+to+controllerto get value of selected option from dropdownlist and pass it to controller <p>hello</p> <p>I started with NHibernate &nbsp;and need some help</p> <p>I'm creating a Dropdown as follows</p> <p></p> <p>In my Controller</p> <pre class="prettyprint">ViewBag.h=new SelectList(new Hobby_MasterService().GetHobbies(),&quot;Hobby_Id&quot;);</pre> <pre class="prettyprint">and in view</pre> <p>&lt;b&gt;Select Hobby:&lt;/b&gt;<br> @using (Html.BeginForm())<br> {<br> &lt;div class=&quot;Editor-field&quot;&gt;<br> @Html.DropDownListFor(Model =&gt; Model.Hobby_Id,ViewBag.h as SelectList)<br> &lt;/div&gt;<br> &lt;input type=&quot;submit&quot; value=&quot;Search&quot; /&gt;<br> <br> }</p> <p></p> <p>but in the controller post action i get id as null</p> <p>please help</p> <p></p> 2012-03-21T06:03:09-04:004890722http://forums.asp.net/p/1783013/4890722.aspx/1?Re+to+get+value+of+selected+option+from+dropdownlist+and+pass+it+to+controllerRe: to get value of selected option from dropdownlist and pass it to controller <p></p> <blockquote><span class="icon-blockquote"></span> <h4>priya77</h4> but in the controller post action i get id as null</blockquote> <blockquote><span class="icon-blockquote"></span> <h4>priya77</h4> @Html.DropDownListFor(Model =&gt; Model.Hobby_Id,ViewBag.h as SelectList)</blockquote> <p></p> <p>Either add an instance of the Model as parameter to the action ( recommended) , either change in the action from id in Hobby_Id</p> 2012-03-21T06:11:13-04:004890767http://forums.asp.net/p/1783013/4890767.aspx/1?Re+to+get+value+of+selected+option+from+dropdownlist+and+pass+it+to+controllerRe: to get value of selected option from dropdownlist and pass it to controller <p>Hello sir,</p> <p>did u mean by that is i haveto create an action linkinstead of button</p> <p>please giv sum example</p> 2012-03-21T06:37:17-04:004891005http://forums.asp.net/p/1783013/4891005.aspx/1?Re+to+get+value+of+selected+option+from+dropdownlist+and+pass+it+to+controllerRe: to get value of selected option from dropdownlist and pass it to controller <p></p> <blockquote><span class="icon-blockquote"></span> <h4>priya77</h4> did u mean by that is i haveto create an action linkinstead of button</blockquote> <p></p> <p>No! Use the submit!</p> <p>Ok, a way of 2: public ACtionResult YourAction(Hobby_Id int)</p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>priya77</h4> please giv sum example</blockquote> <p></p> <p>Did you follow any of tutorials from http://www.asp.net/mvc ?</p> 2012-03-21T08:46:25-04:004891012http://forums.asp.net/p/1783013/4891012.aspx/1?Re+to+get+value+of+selected+option+from+dropdownlist+and+pass+it+to+controllerRe: to get value of selected option from dropdownlist and pass it to controller <p>I did the same thing in my actionResult on controller</p> <p>bt it says it is getting null value</p> <p>I had gone through Music store application</p> 2012-03-21T08:50:03-04:004891078http://forums.asp.net/p/1783013/4891078.aspx/1?Re+to+get+value+of+selected+option+from+dropdownlist+and+pass+it+to+controllerRe: to get value of selected option from dropdownlist and pass it to controller <p></p> <blockquote><span class="icon-blockquote"></span> <h4>priya77</h4> <p></p> <p>I did the same thing in my actionResult on controller</p> <p>bt it says it is getting null value</p> <p></p> </blockquote> <p></p> <p>Code , please?</p> 2012-03-21T09:11:44-04:004891094http://forums.asp.net/p/1783013/4891094.aspx/1?Re+to+get+value+of+selected+option+from+dropdownlist+and+pass+it+to+controllerRe: to get value of selected option from dropdownlist and pass it to controller <p>in my controller:</p> <p></p> <p>public ActionResult Details()<br> {<br> <br> ViewBag.h=new SelectList(new Hobby_MasterService().GetHobbies(),&quot;Hobby_Id&quot;);</p> <p>return View();<br> }<br> [HttpPost]<br> public ActionResult Details(int Hobby_Id)</p> <p>{</p> <p>&nbsp;Hobby_Master hm = new Hobby_MasterService().GetHobby_Data(Hobby_Id);</p> <p>return View(hm);</p> <p>}</p> <p></p> 2012-03-21T09:18:02-04:004891117http://forums.asp.net/p/1783013/4891117.aspx/1?Re+to+get+value+of+selected+option+from+dropdownlist+and+pass+it+to+controllerRe: to get value of selected option from dropdownlist and pass it to controller <p>1. </p> <blockquote><span class="icon-blockquote"></span> <h4>priya77</h4> public ActionResult Details(int Hobby_Id)</blockquote> <p></p> <p>And how do you know it is null? int can not have null ...<br> <br> 2. In the HttpPost action you should fill again the ViewBag.h</p> 2012-03-21T09:29:59-04:004891148http://forums.asp.net/p/1783013/4891148.aspx/1?Re+to+get+value+of+selected+option+from+dropdownlist+and+pass+it+to+controllerRe: to get value of selected option from dropdownlist and pass it to controller <p>1. Actly sir it was giving sum error as parameter &quot;Hobby_Id&quot; is null</p> <p>so i said that</p> <p>2.Now its not giving any error bt not showing any data</p> <p>shal i attach a new data to jst show the result??</p> <p></p> 2012-03-21T09:44:28-04:004891159http://forums.asp.net/p/1783013/4891159.aspx/1?Re+to+get+value+of+selected+option+from+dropdownlist+and+pass+it+to+controllerRe: to get value of selected option from dropdownlist and pass it to controller <p>1. </p> <blockquote><span class="icon-blockquote"></span> <h4>priya77</h4> Actly sir it was giving sum error as parameter &quot;Hobby_Id&quot; is null so i said that</blockquote> <p></p> <p>You did not show any error trace</p> <p>2. </p> <blockquote><span class="icon-blockquote"></span> <h4>priya77</h4> Now its not giving any error bt not showing any data</blockquote> <p></p> <p>That means you pass the hobby id. </p> <p>3.</p> <blockquote><span class="icon-blockquote"></span> <h4>priya77</h4> shal i attach a new data to jst show the result??</blockquote> <p></p> <p>NO idea what you mean by that.</p> <p></p> <p>4. if the VIew have this</p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>priya77</h4> <p></p> <p>@using (Html.BeginForm())<br> {<br> &lt;div class=&quot;Editor-field&quot;&gt;<br> @Html.DropDownListFor(Model =&gt; Model.Hobby_Id,ViewBag.h as SelectList)<br> &lt;/div&gt;<br> &lt;input type=&quot;submit&quot; value=&quot;Search&quot; /&gt;<br> <br> }</p> <p></p> </blockquote> <p></p> <p>What data do you want to show ?</p> <p>5. Did you fill again ViewBag.h in the post action and recompile?</p> 2012-03-21T09:48:29-04:004891186http://forums.asp.net/p/1783013/4891186.aspx/1?Re+to+get+value+of+selected+option+from+dropdownlist+and+pass+it+to+controllerRe: to get value of selected option from dropdownlist and pass it to controller <p>1. Sorry sir it was my mistak that i didnt showed any error trace and i shal keeep this in mind for next time......</p> <p>2.May be yes it is passing id.... but sirin &nbsp;the address bar i can see this...<br> &nbsp;http://localhost:50603/Hobbies/Details?Hobby_Id=Drawing</p> <p>and Hobby_Id inmy db table is a integer field.....den how cum string is cuming here?</p> <p></p> <p>4.I am trying to fetch all the data related to dat id from table lik name,id,details and display it in same page on the page</p> <p>can i do that?? or shal i send this to some other action and try to display it??</p> <p>5.yes i did the same thing and recompild it as u sayed &nbsp;&nbsp;</p> 2012-03-21T09:59:37-04:004891250http://forums.asp.net/p/1783013/4891250.aspx/1?Re+to+get+value+of+selected+option+from+dropdownlist+and+pass+it+to+controllerRe: to get value of selected option from dropdownlist and pass it to controller <p></p> <blockquote><span class="icon-blockquote"></span> <h4>priya77</h4> 2.May be yes it is passing id.... but sirin &nbsp;the address bar i can see this...<br> &nbsp;http://localhost:50603/Hobbies/Details?Hobby_Id=Drawing</blockquote> <p></p> <p>This is how the dropdown list have it's text and value, and ultimately, how do you put into ViewBag.h</p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>priya77</h4> <p></p> <p>4.I am trying to fetch all the data related to dat id from table lik name,id,details and display it in same page on the page</p> <p>can i do that?? or shal i send this to some other action and try to display it??</p> <p></p> </blockquote> <p></p> <p>Of course. Again, the question is very basic. Follow tutorials from http://www.asp.net/mvc</p> 2012-03-21T10:34:18-04:00