Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC3 ASP.NET Can I reload my view when validating a form nested within a partial view?
    primarykey
    data
    text
    <p>I have a partial view that I'm using on my index page to display a form. When an item is selected from a dropdown menu on the index page, the partial view is loaded with corresponding form data. I need to validate the form when submitted, but I'm not sure what to return from my controller that will load the page correctly when displaying errors. My submit button is currently on my partial view. (I tried moving the submit to the Index page, but it did not return anything from the form.) If there are validation errors, the partial view loads, but the dropdown menu from the Index view does not. I've seen a few solutions to this issue but none have worked in this situation, probably due to the dropdown. Any help is greatly appreciated. Please let me know if the HTML would be helpful, I was having issues formatting it for this post.</p> <p>Controller:</p> <pre><code>public class PrinterSettingsController : Controller { public ActionResult Index() { ViewBag.Areas = db.Areas.ToList(); PopulateDocumentTypeViewBag(); return View(); } public ActionResult AreaDocumentSettingsList(int areaId = 0) { PopulateDocumentTypeViewBag(); //get area, contains list of document settings } return PartialView("_AreaDocumentSettingsList", selectedArea); } [HttpPost] public ActionResult AreaDocumentSettingsList(Area selectedArea) { if (IsPrinterValid(selectedArea.PrinterName) == false) { ModelState.AddModelError(string.Empty, "Incorrect printer path entered."); } if (ModelState.IsValid) { //do some stuff, save the new records to the database db.Entry(originalAreaRecord).CurrentValues.SetValues(selectedArea); db.SaveChanges(); //if everything saves fine, go to a different page return RedirectToAction("Index", "Workorder"); } //if there are errors -- this part needs to be changed -- show errors in partial view, but also display view it's nested inside of return View("_AreaDocumentSettingsList", selectedArea); } </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