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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:40:16+00:00 2026-06-02T18:40:16+00:00

I have a ajax post which give me the values from what the user

  • 0

I have a ajax post which give me the values from what the user have typed into my form.

And in my database I have two entites that are being used and I use model first.
However Im getting “Object reference not set to an instance of an object” error when trying to do this:

goalCardQuestionAnswer.SelectedQuestion.Id = selectedQuestionViewModel.QuestionID;

This is my controller post:

    [HttpPost]
    public bool AnswerForm(SelectedQuestionViewModel selectedQuestionViewModel)
    {
        if (ModelState.IsValid)
        {
        var goalCardQuestionAnswer = new GoalCardQuestionAnswer();

        goalCardQuestionAnswer.SelectedQuestion.Id = selectedQuestionViewModel.QuestionID;
        goalCardQuestionAnswer.Comment = selectedQuestionViewModel.Comment;
        goalCardQuestionAnswer.Grade = selectedQuestionViewModel.Grade;

        answerNKIRepository.SaveQuestionAnswer(goalCardQuestionAnswer);
        answerNKIRepository.Save();

        }

My SelectedQuestionViewModel:

   public class SelectedQuestionViewModel
{

    public int? Grade { get; set; }
    public string Comment { get; set; }
    public string SelectedQuestionText { get; set; }
    public int QuestionID { get; set; }

}

My database model

enter image description here

  • 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-02T18:40:18+00:00Added an answer on June 2, 2026 at 6:40 pm

    You must initialize your SelectedQuestion property:

    var goalCardQuestionAnswer = new GoalCardQuestionAnswer();
    goalCardQuestionAnswer.SelectedQuestion = new SelectedQuestion();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a AJAX post method that gets xml data from server. But when
i have the following javascript to post a form through ajax without refreshing the
I have this code that works well: {livre:empty_name} $.ajax({ url: sent.php, type: post, dataType:
Hey guys, I have a program that uses ajax to send a post to
i have code like this. which is actually a form .which lets user updates
Hey guys I have an ajax jquery function that receives data from a php
Suppose I have setInterval(PostToServer, 1000); . PostToServer function makes ajax post, which may take
I have form which data will be sent via ajax. It is normal string-type
I have an Ajax post call written in a separate .js file which I
I'm having problems with understanding how jQuery create headers for ajax post. I have

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.