Answer the question
In order to leave comments, you need to log in
How to build the structure of html input' s so that the Action accepts a serialized object?
example:
ObjectModel
public int id;
public string password;
public bool tired;
public void Action(ObjectModel[] objects)
public void Action(int[] ids, string[] passwords, bool[] tireds)
@foreach (var obj in Model) {
@Html.TextBoxFor(m => obj.Id) <br />
@Html.TextBoxFor(m => obj.password) <br />
@Html.CheckBoxFor(m => obj.tired) <br />
<br />
<br />
}
<input data-val="true" data-val-number="Значением поля Id должно быть число." data-val-required="Требуется поле Id." id="obj_Id" name="obj.Id" type="text" value="109" /> <br />
<input id="obj_password" name="obj.password" type="text" value="reader" /> <br />
<input data-val="true" data-val-required="Требуется поле tired." id="obj_tired" name="obj.tired" type="checkbox" value="true" />
<input name="obj.tired" type="hidden" value="false" /><br /><br /><br />
<input id="obj_Id" name="obj.Id" type="text" value="108" /> <br />
<input id="obj_password" name="obj.password" type="text" value="reguser" /> <br />
<input id="obj_tired" name="obj.tired" type="checkbox" value="true" /><input name="obj.tired" type="hidden" value="false" /> <br /><br /><br />
<input id="obj_Id" name="obj.Id" type="text" value="4" /> <br />
<input id="obj_password" name="obj.password" type="text" value="Зарегистрированный пользователь" /> <br />
<input id="obj_tired" name="obj.tired" type="checkbox" value="true" /><input name="obj.tired" type="hidden" value="false" /> <br /><br /><br />
Answer the question
In order to leave comments, you need to log in
offtopic. oh my god. How terrible does this code look?
Purely theoretically, you need to form inputs as follows:
<div>
<input name="[0]obj.Id" type="text" /> <br />
<input name="[0]obj.password" type="text" /> <br />
<input name="[0]obj.tired" type="text"/><br />
</div>
<div>
<input name="[1]obj.Id" type="text" /> <br />
<input name="[1]obj.password" type="text" /> <br />
<input name="[1]obj.tired" type="text" /><br />
</div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question