I have a boolean variable within my model assigned as false, which i am then using in my view within a checkbox in order to obtain true or false based on whether the checkbox is ticked or not.
In my view:
@using (Html.BeginForm("Items", "Items", FormMethod.Post, new { id = "checkBoxForm" } ))
{
@Html.CheckBoxFor(x => x.ItemList.itemCheck)
}
In my ActionResult:
[HttpPost]
public ActionResult Items(string ItemDescription, CategoryItemViewModel model)
{
var FkFile = Server.MapPath("~/App_Data/ForeignKeyValue.txt");
var Fk = System.IO.File.ReadAllText(FkFile);
var dataFileItems = Server.MapPath("~/App_Data/Item.txt");
var numberOfLinesItems = System.IO.File.ReadLines(dataFileItems).Count();
var textFileDataItems = model.ItemList.itemCheck + Environment.NewLine;
System.IO.File.AppendAllText(dataFileItems, textFileDataItems);
return View();
}
I have tried to pass this value through 'model.ItemList.itemCheck', however when this ActionResult is executed, i receive a " System.NullReferenceException: 'Object reference not set to an instance of an object.' " error.
Aucun commentaire:
Enregistrer un commentaire