Reputation: 299
I created a list based on the scaffolding
@model IEnumerable<FleetLink.Domain.Entities.UserTable>
@using (Html.BeginForm("Index", "Home", FormMethod.Post))
{
<table>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Master_IP)
@Html.TextBoxFor(modelItem=>item.Master_IP)
</td>
<td>
@Html.DisplayFor(modelItem => item.Master_Name)
</td>
</tr>
<tr><td><input type="submit" value="Submit" /></td></tr>
</table>
}
In my controller I have a get and a post method for index
[HttpPost]
public ActionResult Index(List<UserTable> list)
{
return View();
}
[HttpGet]
public ActionResult Index()
{
var users= from userTable in _repo.GetUsers()
select userTable;
return View(users);
}
I was expecting it would call post method when I clicked on submit and would pass the entire tables data to the Index HTTPPost method. But it is always calling the get method of Index. The goal is to pass entire table data after user edits it so I can save all table data at once. Please advice on what I am doing wrong.
Upvotes: 2
Views: 3084
Reputation: 299
I resolved this issue by changing the foreach to for(int i=0....) as well as changing the @using (Html.BeginForm("Index", "Home", FormMethod.Post)) to @using (Html.BeginForm(FormMethod.Post))
Thanks
Upvotes: 1