Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating only the partial view contained in a mvc 3 page?
    primarykey
    data
    text
    <p>I have a <strong>MVC 3</strong> page that returns a list of user responses with a partial view called "memo" (which displays/add memos) for each response. When I add a memo to a response, it should update the db and the list of memos for that response. It should be partial page update via ajax, which effects only the partial view "memo". </p> <p>The view Response.chtml that contains "memo":</p> <pre><code>@using (Html.BeginForm("Response", "User", FormMethod.Post, new { id = "UserResponse" })) { .... code removed .... @foreach (var response in Model) { &lt;div class="qna"&gt;&lt;input type="text" id=@response.responseId value="@response.ResponseText" /&gt; &lt;div&gt;@Html.Partial("_memo", response.responseId)&lt;/div&gt; } ..... </code></pre> <p>The partial page "_memo.chtml":</p> <pre><code>&lt;div&gt;add memo&lt;/div&gt; &lt;ul id="memos"&gt; @foreach (var memo in Model) { &lt;li&gt;@memo.Text&lt;/li&gt; } &lt;/ul&gt; &lt;form method="post" id="memoForm" action="@Url.Action("AddMemo")"&gt; @Html.TextArea("Memo", new { rows = 5, cols = 50 }) &lt;br /&gt; &lt;input type="submit" value="Add" /&gt; &lt;/form&gt; </code></pre> <p>Controller for view User/Response:</p> <pre><code>[HttpGet] public ActionResult Response(id) { ..... return View(responses); </code></pre> <p>I just started with the code above, need help filling the blanks. </p> <ol> <li><p>If I pass the response Id to the partial view, how do I pull the list of memos for that response? Will it involve ajax? (instead of ..<code>Partial("_memo", response.memos)</code>)</p></li> <li><p>How do I update the partial view via ajax call. What is ajax call (sample code) on the client side and how would the controller look? When the ajax call is successful, how do I update the list memos <code>div="memos"</code> to reflect the new memo? </p></li> <li><p>Will the form action from Response conflict with form action of the partial view Memo?</p></li> </ol>
    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.
 

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