Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This was my fix.</p> <p>I rendered a partial view</p> <p>Main View</p> <pre><code>&lt;div class="asideRight"&gt; &lt;fieldset&gt; &lt;legend&gt;&lt;/legend&gt; @Html.Partial("_AddCat", new Exercise4.Models.Category()) &lt;/fieldset&gt; &lt;/div&gt; </code></pre> <p>Partial View</p> <pre><code>@model Exercise4.Models.Category &lt;script src="~/Scripts/jquery-1.7.1.min.js"&gt;&lt;/script&gt; &lt;script src="~/Scripts/jquery.validate.min.js"&gt;&lt;/script&gt; &lt;script src="~/Scripts/jquery.validate.unobtrusive.min.js"&gt;&lt;/script&gt; @using (Html.BeginForm("addCat", "Quote")) { @Html.ValidationSummary(true) &lt;fieldset&gt; &lt;legend class="myLegend"&gt;Create New Category&lt;/legend&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.CatName) &lt;/div&gt; &lt;p&gt; &lt;input class="mySubmit" type="submit" value="Create" /&gt; &lt;/p&gt; &lt;/fieldset&gt; &lt;div class="myValidation"&gt; @Html.ValidationMessageFor(model =&gt; model.CatName) @Html.ValidationMessage("") &lt;/div&gt; } </code></pre> <p>This allowed me to post back to the controller and add the new category before returning to the Create View</p> <p>Controller Method</p> <pre><code> [HttpPost] [Authorize] public ActionResult addCat(Category cat) { if (cat.CatName != null) { bool exists = db.Categories.Any(n =&gt; n.CatName.ToLower() == cat.CatName.ToLower()); if (!exists) { db.Categories.Add(cat); db.SaveChanges(); } else { ModelState.AddModelError("", "You entered a duplicate Category Name"); } } ViewBag.CategoryID = new SelectList(db.Categories.OrderBy(n =&gt; n.CatName), "CategoryID", "CatName"); return RedirectToAction("Create"); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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