Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Member
7 Points
69 Posts
Apr 28, 2012 04:13 AM|LINK
I wrote the following code but I got 13 drop down lists with 13 items(in table name field have 13 items) but I need 1 only how to resolve this here is my controller private sampleEntities db = new sampleEntities(); public ActionResult Index() { var GenreLst = new List<string>(); var GenreQry = from d in db.emps orderby d.name select d.name; GenreLst.AddRange(GenreQry.Distinct()); ViewBag.movieGenre = new SelectList(GenreLst); return View(db.emps.ToList()); view: }<h2>Index</h2> <%:ViewBag.Title="Index" %> <p> <%: Html.ActionLink("Create New", "Create") %> </p> <table> <tr> <th> name </th> <th></th> </tr> <% foreach (var item in Model) { %> <tr> <td> <%:Html.DropDownList("movieGenre") %> </td> <td> <%: Html.ActionLink("Edit", "Edit", new { id=item.Id }) %> | <%: Html.ActionLink("Details", "Details", new { id=item.Id }) %> | <%: Html.ActionLink("Delete", "Delete", new { id=item.Id }) %> </td> </tr> <% } %> </table> </asp:Content>
asp.netmvc3
chandana G
Member
7 Points
69 Posts
Re: how to save a item in the database when we select that item from drop down list in mvc3 app
Apr 28, 2012 04:13 AM|LINK
I wrote the following code but I got 13 drop down lists with 13 items(in table name field have 13 items)
</div> </div>but I need 1 only how to resolve this
here is my controller
private sampleEntities db = new sampleEntities();
public ActionResult Index()
{
var GenreLst = new List<string>();
var GenreQry = from d in db.emps
orderby d.name
select d.name;
GenreLst.AddRange(GenreQry.Distinct());
ViewBag.movieGenre = new SelectList(GenreLst);
return View(db.emps.ToList());
view:
}<h2>Index</h2>
<%:ViewBag.Title="Index" %>
<p>
<%: Html.ActionLink("Create New", "Create") %>
</p>
<table>
<tr>
<th>
name
</th>
<th></th>
</tr>
<% foreach (var item in Model) { %>
<tr>
<td>
<%:Html.DropDownList("movieGenre") %>
</td>
<td>
<%: Html.ActionLink("Edit", "Edit", new { id=item.Id }) %> |
<%: Html.ActionLink("Details", "Details", new { id=item.Id }) %> |
<%: Html.ActionLink("Delete", "Delete", new { id=item.Id }) %>
</td>
</tr>
<% } %>
</table>
</asp:Content>
asp.netmvc3