Gestion des Dropdownlist ASP.NET C#
j'ai cree un formulaire qui contient une dropDowList sous asp dot net MVC2
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| <h2>Create</h2>
<% using (Html.BeginForm()) {%>
<%= Html.ValidationSummary(true) %>
<fieldset>
<legend>Fields</legend>
<div class="editor-label">
<%= Html.LabelFor(model => model.Description) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.Description) %>
<%= Html.ValidationMessageFor(model => model.Description) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.DateDebut) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.DateDebut) %>
<%= Html.ValidationMessageFor(model => model.DateDebut) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.duree) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.duree) %>
<%= Html.ValidationMessageFor(model => model.duree) %>
</div>
<div>
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource1" DataTextField="Libelle" DataValueField="IdSalle">
</asp:DropDownList>
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset> |
viola l'action create asocier au button create
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| [AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create(Reunion reunionToCreate)
{
if (!ModelState.IsValid)
return View();
try
{
_db.AddToReunions(reunionToCreate);
_db.SaveChanges();
return RedirectToAction("Index");
}
catch
{
return View();
}
} |
moi dans le controle je veux recuperer la valeur seletioner dans la dropdawnlist pour l'afecter a un champ de l'objet reunion