I pass some dummy data to my View just to have something to work with :
public ActionResult Index()
{
ViewBag.Message = "Create table";
var model = new List<Auction>();
model.Add(new Auction
{
Title = "First Title",
Description = "First Description"
});
model.Add(new Auction
{
Title = "Second Title",
Description = "Second Description"
});
model.Add(new Auction
{
Title = "Third Title",
Description = "Third Description"
});
model.Add(new Auction
{
Title = "Fourht Title",
Description = "Fourth Description"
});
return View(model);
}
I display this in my view :
@model List<Ebuy.Website.Models.Auction>
@{
ViewBag.Title = "Home Page";
}
@using (Html.BeginForm())
{
<table border="1" >
@for (var i = 0; i < Model.Count(); i++)
{
<tr>
<td>
@Html.HiddenFor(x => x[i].Id)
@Html.DisplayFor(x => x[i].Title)
</td>
<td>
@Html.EditorFor(x => x[i].Description)
</td>
</tr>
}
</table>
<button type="submit">Save</button>
}
and now I want to make some manipulation of the submitted data :
[HttpPost]
public ActionResult Index(List<Auction> model)
{
var test = model;
model[1].Title = "Test";
return View(model);
}
But when I debug this I see that the Description properties are send back but the Title properties don't have value. As you can see above I display them with @Html.DisplayFor(x => x[i].Title). Is this some default behaviour or am I doing something wrong?