What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 7657 |  Welcome, Guest!   Register  Login
 Home > Code Snippets > ASP.NET > Populating dropdowlist dynamically in mvc ...
Maheshvishnu

Populating dropdowlist dynamically in mvc

 Code Snippet posted by: Maheshvishnu | Posted on: 9/4/2012 | Category: ASP.NET Codes | Views: 468 | Status: [Member] | Points: 40 | Alert Moderator   



VIEW:


Pass viewdata attribute in dropdownlist html designing code

Html.DropDownList("CarsList", new SelectList((IEnumerable)ViewData["CarsList"], "ID", "Name"))




CONTROLLER:


first get required data from database and then pass the resultant data to view from controller using viewdata attribute


public ActionResult GetData()
{
var CarNames = from c in obj.Cars
select c;

ViewData["Carsist"] = CarNames;

return View();
}

mahesh
Found interesting? Add this to:


 Responses

T.Saravanan
Posted by: T.Saravanan | Posted on: 9/5/2012 | Level: Silver | Status: [Member] [MVP] | Points: 10 | Alert Moderator 

Kindly post your code inside the code tag.

Thanks,
T.Saravanan

Maheshvishnu
Posted by: Maheshvishnu | Posted on: 9/5/2012 | Level: Starter | Status: [Member] | Points: 10 | Alert Moderator 

@using (Html.BeginForm("BindHRlist", "Appraisal", FormMethod.Post))
{
<div style="float: left; width: 100%">
<br />
<div>
Account:
@Html.DropDownList("CarsList", new SelectList((System.Collections.IEnumerable)ViewData["CarsList"], "Id", "Name"), new { id = "ddlCars" })
</div>
}

mahesh

>> Write Response - Respond to this post and get points

More codes snippets

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/25/2013 5:11:55 PM