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

  • Home
  • SEARCH
  • 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 8630027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:57:29+00:00 2026-06-12T08:57:29+00:00

I’ve been learning MVC3 in the last few weeks and I’m trying to write

  • 0

I’ve been learning MVC3 in the last few weeks and I’m trying to write what I believe should be a simple enough piece of functionality, but I’m having real problems getting it to work correctly.

The scenario

My website will contain news posts, summarised on the home page, with links to view the full details of each article in it’s own page.

Comments can be made on each article, and these comments are shown at the end of each article’s details page. Authenticated users should be able to post their own comments to the article from the page that shows the article itself. I want to avoid users being taken to a seperate page (although I understand this is easier from a code perspective, I disagree that it’s a good UX!).

For an example of how I want this to look, Scott Hanselman’s blog (http://www.hanselman.com) is a perfect example (albeit that his home page shows the entire article rather than just a summary!) – it links through to the comments page, and the “Add comments” form sits neatly at the bottom, inline with the article.

Where I’m at so far

I’ve managed to write the Controller for my news section, with an Index method (which retrieves X number of most recent posts) and a “Comments” method to show the full article and comments. I’ve also created a partal view called “CommentForm” with it’s own Controller method. Code snippets from the controller below:

//
// GET: /News/ 
public ActionResult Index()
{
    using (var nm = new NewsManager())
    {
        var news = nm.GetLatestActiveNewsArticles(50, "System");
        return View(news);
    }
}
//
// GET: /News/Comments/20
public ActionResult Comments(int id)
{
    using (var nm = new Rapallo.Core.Managers.NewsManager())
    {
        var article = nm.GetArticle(id);
        return View(article);
    }
}
// GET: /News/CommentForm/20
[HttpGet()]
public ActionResult CommentForm(int newsId)
{
    return View(new Rapallo.DataAccess.Comment() { NewsId = newsId });
}
// 
// POST: /News/Comments/20
[Authorize()]
[HttpPost()]
public ActionResult Comments(Comment comment)
{
    using (var nm = new NewsManager())
    {
        var article = nm.GetArticle(comment.NewsId.Value);
        if (null == article) HttpNotFound();
    }
    using (var cm = new CommentManager())
    {
        if (cm.AddCommentToNews(comment.NewsId.Value, CurrentUser.RapalloUser.Id, comment.Body))
        return RedirectToAction("Comments", "News", new { id = comment.NewsId.Value });
    }
    return HttpNotFound();
}

And from the Comments view, the code snippet to show where I’d like my add comment form:

@if (User.Identity.IsAuthenticated)
{
    @Html.Partial("Comment", new Rapallo.DataAccess.Comment() { NewsId = Model.Id });
}

This view specifies:

@model Rapallo.DataAccess.News

And finally, the comment form itself:

@model Rapallo.DataAccess.Comment
@using (Html.BeginForm())
{ 
    @Html.TextAreaFor(m => m.Body);
    <input type="submit" value="Send Comment" />
}

The problem

In a nutshell, when I submit the comment form (which renders correctly), NewsId on the Comment model is not populated so the controller cannot associate the new comment with the correct news post.

I’d appreciate if someone could point out where I’m going wrong! I’ve tried to adapt some code from NerdDinner to make this work, as well as spending countless hours on the train trying various combinations of partial views, different models, and even renaming methods in my controller in an attempt to get this to work.

I’m quite keen on encapsulating the “add comment” functionality into it’s own separate form and being able to use this to add comments to more than just news articles. The database schema and domain models already support this, I just can’t get the UI to work.

Any help would be very welcome and gratefully received.

  • 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-12T08:57:31+00:00Added an answer on June 12, 2026 at 8:57 am

    The simple answer is that you need to have a representation of the NewsId on your form for the model binder to find it. So, change your comment form to:

    @model Rapallo.DataAccess.Comment
    @using (Html.BeginForm())
    { 
        @Html.HiddenForm(m => m.NewsId);
        @Html.TextAreaFor(m => m.Body);
        <input type="submit" value="Send Comment" />
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group

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.