Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ideally, I believe the form should submit to a single action.</p> <p>So the controller may look like this:</p> <pre><code>public class HomeController : Controller { public ViewResult Index() { return View(); } [HttpPost] public ActionResult Index(ItemModel itemModel, string submit) { //I'm not sure why I need this but the fields display with empty results on my machine otherwise ModelState.Clear(); if (submit == "edit") { this.TempData.Add("item", itemModel); return View("ChangeImage", new ImageModel { ImageName = itemModel.ImageName }); } else { //perform save here return RedirectToAction("ViewAfterSavePerformed"); } } [HttpPost] public ViewResult Image(ImageModel imageModel) { ItemModel itemModel = (ItemModel)this.TempData["item"]; itemModel.ImageName = imageModel.ImageName; return View("Index", itemModel); } } </code></pre> <p>With the following view models:</p> <pre><code>public class ItemModel { public string Description { get; set; } public string ImageName { get; set; } } public class ImageModel { public string ImageName { get; set; } } </code></pre> <p>And the following views:</p> <p><strong>Index:</strong></p> <pre><code>&lt;h2&gt;Index&lt;/h2&gt; @using (Html.BeginForm()) { &lt;p&gt;Description: @Html.EditorFor(m =&gt; m.Description)&lt;/p&gt; &lt;p&gt;Image: @Html.EditorFor(m =&gt; m.ImageName)&lt;/p&gt; &lt;input type="submit" name="submit" value="edit" /&gt; &lt;input type="submit" name="submit" value="save" /&gt; } </code></pre> <p><strong>Change Image:</strong></p> <pre><code>&lt;h2&gt;ChangeImage&lt;/h2&gt; @using (Html.BeginForm("Image", "Home")) { &lt;p&gt;Image: @Html.EditorFor(m =&gt; m.ImageName)&lt;/p&gt; &lt;input type="submit" name="submit" value="save image" /&gt; } </code></pre> <p>Hopefully this should may sense even though i've used razor syntax.</p>
    singulars
    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.
    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