I am not really sure what you're asking here. You don't need any kind of hidden field to post the selected values of a dropdown. Your Dropdownlist code is invalid to begin with.
Up vote 0 down vote favorite share g+ share fb share tw.
I need to pass multiple data ( probably 2 Html. DropDownList's selected values ) to MVC controller action method from MVC View ( . Aspx).
I think it would be from somehow Html. Hidden form , but how? I am unable to get the selected value from Html.
DropDownList and pass it as Html. Hidden("paramName", MvcStringSelectedValue) to controller's action. My Code is : based on Do I need to write the input tag of "submitt" 2 times or just only once?
Edit ( EXTRA CODE ) Controller's action method : HttpPost public ActionResult CloneSemesterData(string strSemesterToOrganize, string strSemesterToBaseOn) { ............................................................. .............................. } HERE ( another Controller's method ) IS THE DROP DOWN LIST Filled with Semester values public ActionResult DepartmentAdministration() { // Get list of semesters var lr = new ListRepository(); ViewData"Semester" = new SelectList(lr. ListSemester(3)); //this ListSemester(3) will generate the list with 3 strings ( e. G "WS 2012", "SS2010") return View(); } My View code in .
Aspx file is : //this executes when radioButton ="Clone" is selected // this is First drop down list box , from which selected value , I want to transfer as 1st parameter of controller's action method based On //this is Second drop down list box, from which selected value, I want to transfer as 2nd parameter of controller's action method. ERROR: Now, after fixing using Edit 2 : it is giving red lines under as it is somehow not recognizing the ViewData"SemesterList"... "System.Web.Mvc. HtmlHelper does not contain a definition for 'DropDownList' and the best extension method overloaded 'System.Web.Mvc.Html.
SelectExtensions. DropDownList(System.Web.Mvc. HtmlHelper, string,System.Collections.Generic.
IEnumerable') has some invalid arguments". Hope now it will clear, still ambiguity , do let me know then. Regards Usman asp.
Net-mvc mvc view dropdownlist selectedvalue link|improve this question edited 16 hours ago asked 18 hours agoUsman222110 65% accept rate.
Please post your controller action you need to call once Submit is clicked and the controller that populates your DropDownLists... with that we can see and correct what you are doing ;) – Romias 17 hours ago.
I am not really sure what you're asking here. You don't need any kind of hidden field to post the selected values of a dropdown. Your Dropdownlist code is invalid to begin with.
Typically you have something like this: And in your controller: HttpPost public ActionResult MyAction(string SemesterToOrganize, string SemesterToBaseOn) { // your code. } EDIT: Based on what you've told us. You are relying on the behavior of MVC of populating the DropDownList because you are adding your list to the ViewData with the same name as your dropdownlist.
This won't work for you. You will have to populate each dropdown list seperately. In your controller, do something like this: public ActionResult MyAction () { ViewData"SemesterList" = // list of semesters return View(); } Then, in your view you have: then your post method HttpPost public ActionResult MyAction(string SemesterToOrganize, string SemesterToBaseOn) { // your code.
} If you want to continue to argue that you can do it your way, then you won't solve your problem. Each dropdown must have it's own unique id, otherwise it will not post correctly. The only way to solve this problem is to give each it's own unique id.
That breaks the behavior of the drop down automatically getting the data, so you MUST specify the list of data explicitly. So stop arguing that this is an unimportant part of the problem. It's not.
It's key to the problem. EDIT2: Based on your code above: That's all you need If you had just given us this, and didn't argue, this would been solved a lot easier.
Actually I have already a filled Html. DropDownList of smesters ( "SS2012,WS2013, SS2011") and in other Html. DroopDownList the same values, Os I just want to get the selected values from both lists and send them as controller action's parameters.
That's it! – Usman 17 hours ago @Usman - You're not making any sense. You can't fill your drop down lists until you create them.
You creat them with the above code. They automatically post their selected values when you submit the form. What you are describing is impossible given the code you've shown.
– Mystere Man 17 hours ago @Usman - I suggest you provide the real code, not some made up code, because the code you provide is invalid and doesn't show what you're actually trying to do. Use real code. – Mystere Man 17 hours ago This DropDownList is filled in controller's method somehow via some List based list which was filled ( e.
G listofSemester. Add("WS2012") sort of...)just forget it. This posts the correct value when only just one arguemnt is being passed on.
But I need to work with it via 2 list's selection values and these 2 lists must give their selected values somehow to controller's action method – Usman 17 hours ago @Usman - You are asking to forget about something that is critical to solving your problem. If you don't want the advice given, then you won't solve the problem. You're problem is that you're relying on some behavior that won't work in your situation, but you don't want to change it.
– Mystere Man 16 hours ago.
Try this. Change names and put in the appropriate namespace. //Your view @model MvcApplication2.Models.
CloneSemesterDataViewModel @Html. LabelFor(x => x. SemesterToOrganize) @Html.
DropDownListFor(x => x. SemesterToOrganize, Model. ListofSemestersToOrganize) -------- @Html.
LabelFor(x => x. SemesterToBaseOn) @Html. DropDownListFor(x => x.
SemesterToBaseOn, Model. ListofSemestersToBaseOn) //view model namespace MvcApplication2. Models { public class CloneSemesterDataViewModel { public string SemesterToOrganize { get; set; } public IEnumerable ListofSemestersToOrganize { get { return new List { new SelectListItem { Text = "SS2012" , Value = "SS2012"} }; } } public string SemesterToBaseOn { get; set; } public IEnumerable ListofSemestersToBaseOn { get { return new List { new SelectListItem { Text = "SS2012", Value = "SS2012" } }; } } } } ---------- Controller.
HttpPost public ActionResult CloneSemesterData(CloneSemesterDataViewModel viewModel) { //viewModel. SemesterToBaseOn //viewModel. SemesterToOrganize } // This should do the trick.
The view is written for Razor. I guess its straightforward to convert to aspx. – paul 33 mins ago.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.