Reputation: 566
i am currently trying to get data from a form in a view to my controller, i'm sending it a list of object and my goal is to get the one that have been modified by having multiple form. The probleme here is that i don't get anything back from the view, just null values.
@model List<Connection_User>
@for (int i = 0; i < Model.Count ; i++)
{
using(Html.BeginForm("DBLogin","User", FormMethod.Post, new { autocomplete ="off"}))
{
<fieldset>
<div class="editor-label">
@ConsoleV2.Resources.Strings.Name
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model[i].Username)
@Html.ValidationMessageFor(model => model[i].Username)
</div>
<div class="editor-label">
@ConsoleV2.Resources.Strings.Password
</div>
<div class="editor-field">
@Html.PasswordFor(model => model[i].Password)
@Html.ValidationMessageFor(model => model[i].Password)
</div>
<p>
<input type="submit" value="@ConsoleV2.Resources.Strings.Valid" />
</p>
</fieldset>
}
}
and the prototype of my method in the controller is
[HttpPost]
public ActionResult DBLogin(Connection_User Logins)
{
return new EmptyResult();
}
Thanks in advance for your help.
Upvotes: 1
Views: 353
Reputation: 2678
Try foreach
instead of for
@foreach(var modelItem in Model)
{
using(Html.BeginForm("DBLogin","User", FormMethod.Post, new { autocomplete ="off"}))
{
<fieldset>
<div class="editor-label">
@ConsoleV2.Resources.Strings.Name
</div>
<div class="editor-field">
@Html.TextBoxFor(item => modelItem.Username)
@Html.ValidationMessageFor(item => modelItem.Username)
</div>
<div class="editor-label">
@ConsoleV2.Resources.Strings.Password
</div>
<div class="editor-field">
@Html.PasswordFor(item => modelItem.Password)
@Html.ValidationMessageFor(item=> modelItem.Password)
</div>
<p>
<input type="submit" value="@ConsoleV2.Resources.Strings.Valid" />
</p>
</fieldset>
}
}
Upvotes: 1