Im trying to insert data into a table on my main view from my HomeController and it is returning a null exception and I cant figure out why.
My controller:
public ActionResult FillTable()
{
var MyState = new State();
var StateValues1 = new State();
StateValues1.DayTableDates = "monday";
StateValues1.DayTableValues = "15";
MyState.TableValuess.Add(StateValues1);
return View(MyState);
}
My view:
@{
var StateValues1 = Model.TableValuess.FirstOrDefault();
}
<table class="greyGridTable">
<thead>
<tr>
<th>Date</th>
<th>Value</th>
</tr>
</thead>
<tr>
<td>@StateValues1.DayTableDates</td>
<td>@StateValues1.DayTableValues</td>
</tr>
</table>
my Model:
public class State
{
public List<State> TableValuess = new List<State>();
public string DayTableDates { get; set; }
public string DayTableValues { get; set; }
}
my index method: Index method
Im fairly new to MVC but in my head this should work. Excuse the variable names, ive been messing with it for quite a while now.
Thanks for the help
edit: I think the error has something to do with my view being called Index while my action method in the HomeController is called FillTable(). My index method in my controller already has code in it. How would I go about calling my FillTable method or adding my code to the Index method?