I have a DB with below schema
public partial class staging
{
public int id { get; set; }
public System.DateTime createtime { get; set; }
[DataType(DataType.MultilineText)]
public string general { get; set; }
public string articletype { get; set; }
}
I have two views Create and Edit. In Create View I'm updating general but the article type I'm updating from the controller and saving a DB as below
[HttpPost]
[ValidateInput(false)]
public ActionResult Create(staging staging)
{
staging.createtime = DateTime.Now;
staging.articletype = "Stage";
try
{
db.stagings.Add(staging);
db.SaveChanges();
}
catch (InvalidOperationException e)
{
ViewData["error"] = "An error has occured: " + e.Message;
return View(staging);
}
return RedirectToAction("Details/" + staging.id);
}
Now I have a edit field only for general. So when I go to Edit View page I see that articletype has proper value but when it return in to HttpPost of "Edit" the articletype get set to NULL, think it's because I don't have an editor field for the same. And now when I update the DB from Edit Controller it gets set to NULL there as well.
So how can I make this value persistable across views? I will only update in Create event in controller but then I always want that value to be persisted.
Headline