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 8363059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:05:20+00:00 2026-06-09T12:05:20+00:00

I’m working on an mvc .net web application. I hava a database that contains

  • 0

I’m working on an mvc .net web application. I hava a database that contains difficulties (a table called difficultes) and each difficulty has comments.
In my view I want to show every difficulty with its corresponding comments and a text area for a new comment and a button to submit it.
I created a model class that contains a difficulty and comments, a string var for the content of a new comment, and a string var for the name of the person who wants to comment. My problem is that I failed to submit the new comment.

Here is my model class

public class difficultecommentaires
{
    public difficulte diff { get; set; }
    public IList<commentaire> comms { get; set; }
    public string pseudo { get; set; }
    public string nouveau { get; set; }
}

Here is my action method for submitting the new comment

        [HttpPost]
    public ActionResult NewComment(int id_diff, string pseudo, string contenu)
    {
        difficulte d = new difficulte();
        using (BDGestionEntities bd = new BDGestionEntities())
        {
            var query = from j in bd.difficultes where (j.id_diff == id_diff) select j;
            foreach (var k in query)
                d = k;
        }
        commentaire com = new commentaire();
        com.pseudo = pseudo;
        com.difficulte= d;
        com.contenu = contenu;
        db.AddTocommentaires(com);
        db.SaveChanges();
        ObtenirDifficulte(id_diff);
        return View();
    }

And here is my view

 @model GestionProjet.Models.difficultecommentaires

@{
    ViewBag.Title = "ObtenirDifficulte";
}

<h2>Détails</h2>

<fieldset>
<table>
<tr><td>
    <label><b>Titre de la difficulté :</b></label></td><td>@Html.DisplayFor(m=>m.diff.titre)</td></tr>

    <tr><td>
    <label><b>Description :</b></label></td><td>@Html.DisplayFor(m=>m.diff.description)</td></tr>
    </table>
    <table>
    @foreach (var k in Model.comms)
    {

        <tr><td>@k.pseudo a dit :</td><td>
        @k.contenu</td></tr>

    }
    </table>
    <br />
    <table>
    <tr><label><b>Nouveau commentaire</b></label></tr>
    <tr>
    <td><b>Nom :</b></td><td>@Html.TextBoxFor(m=>m.pseudo)</td>
    </tr>
    <tr>
    <td><b>Commentaire :</b></td><td>@Html.TextAreaFor(m=>m.nouveau)</td>
    </tr>
    </table>
    @Html.ActionLink("Ajouter", "NewComment", new { Model.diff.id_diff, Model.pseudo , Model.nouveau}) 

</fieldset>
<p>
<a href="@Url.Action("Index")"><img src="~/Images/retour.png" alt =""/></a>
</p>

And here is my model design (the difficulties part)

enter image description here

I think that the problem is in the parameters of my action link. I an error of null value.
How can I solve this.

  • 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-09T12:05:20+00:00Added an answer on June 9, 2026 at 12:05 pm

    By the looks of it you’re using an ActionLink which will perform a GET (passing the parameters you have given as route parameters, but not the form element values ie. the new comment.) Could try something like below:

    @Html.BeginForm("Ajouter", "NewComment", FormMethod.Post, new { id_diff = Model.diff.id_diff })
        {        
            <table>
                <tr><label><b>Nouveau commentaire</b></label></tr>
                <tr>
                <td><b>Nom :</b></td><td>@Html.TextBoxFor(m=>m.pseudo)</td>
                </tr>
                <tr>
                <td><b>Commentaire :</b></td><td>@Html.TextAreaFor(m=>m.nouveau)</td>
                </tr>
            </table>
    
            <input type="submit" value="Submit" />
        }
    

    And have your action accept:

    [HttpPost]
    public ActionResult NewComment(int id_diff, string pseudo, string contenu)
    {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
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've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.