Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
public ActionResult LoadCountries()
{
     List<SelectListItem> li = new List<SelectListItem>();
     li.Add(new SelectListItem { Text = "Select", Value = "0" });
     li.Add(new SelectListItem { Text = "India", Value = "1" });
     li.Add(new SelectListItem { Text = "Srilanka", Value = "2" });
     li.Add(new SelectListItem { Text = "China", Value = "3" });
     li.Add(new SelectListItem { Text = "Austrila", Value = "4" });
     li.Add(new SelectListItem { Text = "USA", Value = "5" });
     li.Add(new SelectListItem { Text = "UK", Value = "6" });
     ViewData["country"] = li;
     return View();
}



SQL
@using (Html.BeginForm())
{
    @Html.DropDownList("Country", ViewData["country"] as List<SelectListItem>)
}
Posted
Comments
John C Rayan 3-Jul-15 11:37am    
I don't think you could do it without using hidden field and jquery.
Member 11794209 9-Jul-15 1:10am    
How can i pass dropdown selected text to controller without using jquery,Javascript
[httppost]
public ActionResult YourAction(formcollection product)
{
// DROPDOWN TEXT VALUE IS NULL
}
John C Rayan 11-Jul-15 7:31am    
I don't follow you. What you expect from me. You have to either use Jquery or write your own Helper to do it if you do not want to use Jquery
Member 11794209 16-Jul-15 8:54am    
i don't use jquery and javascript
i am mvc razor code
@using (html(BeginForm()){
<input type="submit" id="btnsave" value="save"/>
}
While Pressing the button the values will be binded in controller using formcollection class and i can't bind the drop down text using formcollection can u guide me

John C Rayan 16-Jul-15 9:35am    
How do you bind the dropdown in razor? Can you show me your complete razor view and action method code?

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