Note that there are some explanatory texts on larger screens.

plurals
  1. PORender action return View(); form problem
    primarykey
    data
    text
    <p>I'm new to MVC, so please bear with me. :-)</p> <p>I've got a strongly typed "Story" View. This View (story) can have Comments. </p> <p>I've created two Views (not partials) for my Comments controller "ListStoryComments" and "CreateStoryComment", which do what their names imply. These Views are included in the Story View using RenderAction, e.g.:</p> <pre><code>&lt;!-- List comments --&gt; &lt;h2&gt;All Comments&lt;/h2&gt; &lt;% Html.RenderAction("ListStoryComments", "Comments", new { id = Model.Story.Id }); %&gt; &lt;!-- Create new comment --&gt; &lt;% Html.RenderAction("CreateStoryComment", "Comments", new { id = Model.Story.Id }); %&gt; </code></pre> <p>(I pass in the Story id in order to list related comments).</p> <p>All works as I hoped, except, when I post a new comment using the form, it returns the current (parent) View, but the Comments form field is still showing the last content I typed in and the ListStoryComments View isn’t updated to show the new story.</p> <p>Basically, the page is being loaded from cache, as if I had pressed the browser’s back button. If I press f5 it will try to repost the form. If I reload the page manually (reenter the URL in the browser's address bar), and then press f5, I will see my new content and the empty form field, which is my desired result.</p> <p>For completeness, my CreateStoryComment action looks like this:</p> <pre><code> [HttpPost] public ActionResult CreateStoryComment([Bind(Exclude = "Id, Timestamp, ByUserId, ForUserId")]Comment commentToCreate) { try { commentToCreate.ByUserId = userGuid; commentToCreate.ForUserId = userGuid; commentToCreate.StoryId = 2; // hard-coded for testing _repository.CreateComment(commentToCreate); return View(); } catch { return View(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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