Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>An entire sample of the project is available at <a href="http://www.developer-network.net/downloads/DropDownListErrors.zip" rel="nofollow noreferrer">this url</a></p> <p>These are the action methods.</p> <pre><code>public ActionResult Create() { DatabaseDataContext database = new DatabaseDataContext(); Unit u = new Unit(); u.Sheet = new Sheet(); ViewData["ProductListing"] = new SelectList(database.Products, "ProductId", "ProductName", u.Sheet.ProductId); return View(); } // // POST: /Home/Create [AcceptVerbs(HttpVerbs.Post)] public ActionResult Create(Unit u) { try { DatabaseDataContext database = new DatabaseDataContext(); database.Units.InsertOnSubmit(u); database.SubmitChanges(); // TODO: Add insert logic here return RedirectToAction("Index"); } catch { return View(); } } </code></pre> <p>Here is the Create View.</p> <pre><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage&lt;MVC.Models.Contexts.Unit&gt;" %&gt; &lt;asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"&gt; Create &lt;/asp:Content&gt; &lt;asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"&gt; &lt;h2&gt;Create&lt;/h2&gt; &lt;%= Html.ValidationSummary("Create was unsuccessful. Please correct the errors and try again.") %&gt; &lt;% using (Html.BeginForm()) {%&gt; &lt;fieldset&gt; &lt;legend&gt;Fields&lt;/legend&gt; &lt;%= Html.DropDownList("ProductListing") %&gt; &lt;p&gt; &lt;input type="submit" value="Create" /&gt; &lt;/p&gt; &lt;/fieldset&gt; &lt;% } %&gt; &lt;div&gt; &lt;%=Html.ActionLink("Back to List", "Index") %&gt; &lt;/div&gt; &lt;/asp:Content&gt; &lt;asp:Content ID="Content3" ContentPlaceHolderID="ScriptContent" runat="server"&gt; &lt;/asp:Content&gt; </code></pre>
 

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