Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8864553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:16:07+00:00 2026-06-14T16:16:07+00:00

a bit of a strange one here. I’ve got a blog that’s another ‘dip

  • 0

a bit of a strange one here. I’ve got a blog that’s another ‘dip my toe into MVC’ project that will highlight the benefits of our new Intranet. I have a typical blog post page with the article, comments and a form to submit your comments against a given article.

I have a stringly typed main View (“Post”) which has the article content, then two Html.RenderAction methods; one to get the comments and one to add comments via a form.

My issue is that when a comment is posted, my GetComments method is called before AddComment, so when the page is refreshed the new comment isn’t visible although it has been added to the database. A quick F5 confirms this. I understand that GetComments is being called first due to it being declared first in the view but I’m not sure how to tell the view to do an add before a get.

Here’s my code:

Controller:

public ActionResult AddComment()
    {
        return PartialView("AddComment");
    }

    [HttpPost]
    public ActionResult AddComment(Comment comment)
    {
        comment.DateSubmitted = DateTime.Now;
        db.Comments.Add(comment);
        db.SaveChanges();
        return PartialView(comment);
    }

    public ActionResult GetComments(int articleid)
    {
        var comments = db.Comments.Where(c => c.ArticleID == articleid).ToList();
        return PartialView(comments);
    }

Post view

@model IntranetBlog.Models.Article

@{
ViewBag.Title = "Post";
}

 <div class="row">
<div class="span12">
    <h3>@Html.DisplayFor(modelItem => Model.Title)</h3>
    <small>by Ruth Barlow on @Html.DisplayFor(modelItem => Model.DateCreated)</small>
    @if (Model.Image != null)
    {
        <p>
            <img src="@Url.Action("GetImage", "Home", new { articleID = Model.ArticleID     })" alt="" width="150" height="150" />
        </p>
    }

    <div>
        @Html.DisplayFor(modelItem => Model.Body)
    </div>
    <small>Posted under @Html.DisplayFor(modelItem => Model.Category.Name)</small>
</div>
<div class="span12">
    @{
        Html.RenderAction("GetComments", "Home", new { articleID = Model.ArticleID });
    }
</div>
<div class="span12">
    @{
        Html.RenderAction("AddComment", "Home", new { articleID = Model.ArticleID });
    }
</div>
</div>

GetComments partial:

@model IEnumerable<IntranetBlog.Models.Comment>

@if (Model.Any())
{
<h3>What you're saying</h3>
foreach (var item in Model)
{
    <div>
        Comment: @Html.DisplayFor(modelItem => item.Body)
    </div>
    <div>
        Submitted by: @Html.DisplayFor(modelItem => item.SubmittedBy) 
on @Html.DisplayFor(modelItem => item.DateSubmitted)
    </div>
    <hr />
}
}
else
{
  <p>There are no comments for this post. Why not add one?</p>
}

AddComment partial

@model IntranetBlog.Models.Comment

@using (Html.BeginForm())
{
<h3>Why not leave us a comment?</h3>
@Html.ValidationSummary()
<fieldset>
    <div class="editor-label">
        @Html.LabelFor(model => model.Body)
    </div>
    <div class="editor-field">
        @Html.TextAreaFor(model => model.Body, 20, 20, null)
        @Html.ValidationMessageFor(model => model.Body)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.SubmittedBy)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.SubmittedBy)
        @Html.ValidationMessageFor(model => model.SubmittedBy)
    </div>

    <p>
        <input type="submit" value="Add comment" id="AddComment" class="btn btn-    primary" />
    </p>
</fieldset>
}

Hope this makes sense.
Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T16:16:10+00:00Added an answer on June 14, 2026 at 4:16 pm

    The trick is to use Html.Action instead of Html.RenderAction this will allow you to store the result in a variable and then add it to the display where it is needed.

    This will allow you to generate the PartialView in the logical order you need, while displaying them in an other order.

    See this post for a quick example on how to do it : https://stackoverflow.com/a/13301057/971693

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Bit of a strange problem here... I've got an update query that isn't working,
Bit of a strange one here. I have a bit of javascript that does
Bit of a strange one here, i have a CCTV system and contacted the
A bit of a strange one, I want to write a MySQL query that
I have a strange one here that I just can't seem to figure out.
So here is a bit of a strange one... I have a stored proc
I'm having facing problemind with LDAP, its bit strange one. My Web server is
I have a feeling my problem is a bit strange, but here goes... I
Bit of a strange question here i know. but i wanted to know if
I have a bit of a strange problem. I have a music app that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.