using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Our_Web_Project.Models.Entitiy;
namespace Our_Web_Project.Controllers
{
public class GonderiController : Controller
{
web_siteEntities db = new web_siteEntities();
// GET: Gonderi
public ActionResult Index()
{
return View();
}
public ActionResult Show()
{
var degerler = db.Posts.ToList();
return View(degerler);
}
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(FormCollection form)
{
Posts model = new Posts
{
PostDescription = form["PostDescription"].Trim(),
PostComment = form["PostComment"].Trim(),
};
db.Posts.Add(model);
db.SaveChanges();
return View();
}
}
}
I used form structure to insert data. I am trying to insert PostDescription and PostComment data into SQL. But it shows this error:
System.NullReferenceException Object reference not set to an instance of an object
HResult=0x80004003 line 37
I'm using ASP.NET MVC. What should I do?