Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating an edit form using ASP.Net MVC 2 scaffolding
    text
    copied!<p>I have the following code that was generated using scaffolding and IDJefe is an int in my database, but I want the end users to choose a name from a comboBox.</p> <p>How could I accomplish this?</p> <pre><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage&lt;SeguimientoDocente.Area&gt;" %&gt; &lt;asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"&gt; UTEPSA | Editando Area &lt;/asp:Content&gt; &lt;asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"&gt; &lt;h2&gt;Editando Area: &lt;%: Model.Nombre %&gt;&lt;/h2&gt; &lt;% using (Html.BeginForm()) {%&gt; &lt;%: Html.ValidationSummary(true) %&gt; &lt;fieldset&gt; &lt;legend&gt;Informacion Detallada de Area | &lt;%: Model.Nombre %&gt;&lt;/legend&gt; &lt;div class="editor-label"&gt; &lt;%: Html.LabelFor(model =&gt; model.Nombre) %&gt; &lt;/div&gt; &lt;div class="editor-field"&gt; &lt;%: Html.TextBoxFor(model =&gt; model.Nombre) %&gt; &lt;%: Html.ValidationMessageFor(model =&gt; model.Nombre) %&gt; &lt;/div&gt; &lt;div class="editor-label"&gt; &lt;%: Html.LabelFor(model =&gt; model.IDJefe) %&gt; &lt;/div&gt; &lt;div class="editor-field"&gt; &lt;%: Html.TextBoxFor(model =&gt; model.IDJefe) %&gt; &lt;%: Html.ValidationMessageFor(model =&gt; model.IDJefe) %&gt; &lt;/div&gt; &lt;p&gt; &lt;input type="submit" value="Save" /&gt; &lt;/p&gt; &lt;/fieldset&gt; &lt;% } %&gt; &lt;div&gt; &lt;%: Html.ActionLink("Volver a Listado General", "Index") %&gt; &lt;/div&gt; &lt;/asp:Content&gt; </code></pre> <p>I've tried the following to no avail.</p> <pre><code>&lt;%: Html.DropDownList(Model.Jefes???? %&gt; </code></pre> <p>I could do something like this, but creating a new object for a simple thing like this seems a waste.</p> <pre><code>public ActionResult Edit(int id) { Area area = areaRepository.GetArea(id); JefeRepository jefe = new JefeRepository(); ViewData["Jefes"] = new SelectList(jefe.FindAllJefes(), area.Jefe.Nombre); return View(area); } </code></pre> <p>Is there a better way?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload