'system null reference in .net [duplicate]
When i try to update a value in form its showing system null expression.
here is my code:
[HttpPost]
public ActionResult EditPage(PageMasterViewModels pageupdate,int id)
{
var pagedata = _db.PageMaster.Where(x => x.PageId == id).FirstOrDefault();
if (pagedata != null)
{
pagedata.PageName = pageupdate.PageName;
pagedata.PageMetaTag = pageupdate.PageMetaTag;
pagedata.PageTitle = pageupdate.PageTitle;
pagedata.PageDescription = pageupdate.PageDescription;
pagedata.PageMetaDescription = pageupdate.PageMetaDescription;
pageupdate.UpdatedDate = DateTime.Now;
_db.SaveChanges();
}
return Redirect("PageDetails");
}
Solution 1:[1]
Your pageData's property PageName is Null.If you want to solve this problem you can edit data in your db or change PageData entity to
class PageData{
public string? PageName {get;set;}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Fush1 |

