Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC Partial View to Create/List Items and Redirect
    primarykey
    data
    text
    <p>What I'm trying to achieve is essentially have a view that at the top displays a form to enter new post, then below the form it will display a list of posts that already exist. Also I'm trying to make this view somewhat generic so that it can show different type of posts. </p> <p>To be clear, by post I mean something like a facebook status post and not a Http-Post.</p> <p>Imagine you have home page that displays all the posts, and then you have a profile page that displays only the posts connected to that profile.</p> <p>So I have my _Posts partial view which looks like this:</p> <pre><code>@model IEnumerable&lt;Post&gt; @Html.Partial("_CreatePost", new Post()) @foreach (var item in Model) { &lt;div class="Post"&gt; &lt;h5&gt;@item.Title&lt;/h5&gt; &lt;p&gt;@DateTime.Now.Subtract(item.Date).ToString("mm") minutes ago&lt;/p&gt; &lt;p&gt;@item.Content&lt;/p&gt; &lt;/div&gt; } </code></pre> <p>The code for the partial view is:</p> <pre><code>@model MVC_Test_CRUD.Models.Post &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("Create","Post")) { @Html.ValidationSummary(true) &lt;fieldset&gt; &lt;legend&gt;Post&lt;/legend&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.Title) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.Title) @Html.ValidationMessageFor(model =&gt; model.Title) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.Content) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.Content) @Html.ValidationMessageFor(model =&gt; model.Content) &lt;/div&gt; &lt;p&gt; &lt;input type="submit" value="Create" /&gt; &lt;/p&gt; &lt;/fieldset&gt; } </code></pre> <p>And I successfully display a list of posts and I'm able to create new posts as well.</p> <p>I also have a standard Create Action in my controller, which results in </p> <pre><code>return RedirectToAction("Index") </code></pre> <p>if the creation was successful. So my question is how can I send additional parameter to the controller about where to redirect (home/index or profile/index or somewhere else) depending on where</p> <pre><code>@Html.Partial("_CreatePost", new Post()) </code></pre> <p>was inserted.</p>
    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