My problem is that I am trying to setup a drop down list and when a new item is selected it will update a table of information that I have but every time HttpPost function gets called the parameter is always null. Here is index function of my home controller:
public ActionResult Index()
{
Project[] projects = db.Projects.ToArray();
List<SelectListItem> dropList = new List<SelectListItem>();
BurndownSprintTable[] TableToShow = db.BurndownSprintTables.ToArray();
for (int index = 0; index < projects.Length; ++index)
{
dropList.Add(new SelectListItem { Text = projects[index].Name, Value = projects[index].Id.ToString(), Selected = projects[index].Selected });
if (projects[index].Selected == true)
{
int ProjectId = projects[index].Id;
TableToShow = db.BurndownSprintTables.Where(x => x.ProjectId == ProjectId).ToArray();
}
}
ViewBag.Projects = dropList;
return View(TableToShow);
}
TableToShow is used to show sprint information per project.
Here is the post function:
[HttpPost]
public ActionResult ProjectUpdate(string strProjectId)
{
return View("Index");
}
I realize this post function will cause an error which I believe I can fix on my own but I need strProjectId to not be null.
Here is the html:
@model IEnumerable<TableauConfigWebService.Models.BurndownSprintTable>
@using (Html.BeginForm("ProjectUpdate", "Home", FormMethod.Post))
{
<h5>@Html.DropDownList("Id", (IEnumerable<SelectListItem>)ViewBag.Projects)
<input type="submit" value="Update" /></h5>
}
There is more to it but the rest of the html is setting up a table for the sprint information which works fine.
I have looked around and found a bunch of posts on this but none of them seem to help. I am new to mvc so I know its probably something simple but I cant figure it out.
Thank you for any help.