Моя модель (dto);
public class DTOExample
{
#region Properties
[Required(ErrorMessage = "Required")]
[DataType(DataType.Text)]
[Display(Name = "Name")]
public string Name{ get; set; }
[Required(ErrorMessage = "Required")]
[StringLength(12, ErrorMessage = "{0} alanı en az {1}, en çok {2} karakter olabilir.", MinimumLength = 12)]
[DataType(DataType.Text)]
[Display(Name = "Last Name")]
public string LastName{ get; set; }
[Display(Name = "Send Information")]
public List<DTOSendInformations> ListSend { get; set; }
}
public class DTOSendInformations
{
[Display(Name = "AdressOne")]
[Required(ErrorMessage = "Zorunlu alan")]
[StringLength(50, ErrorMessage = "{0} min {2}, max {1}", MinimumLength = 1)]
[DataType(DataType.Text)]
public string AdressOne{ get; set; }
[Display(Name = "AdressTwo")]
[StringLength(11, ErrorMessage = "{0} min {2}, max {1} karakter olabilir.", MinimumLength = 10)]
[DataType(DataType.Text)]
public string AdressTwo{ get; set; }
}
My View (я написал необходимые части)
<div class="row">
<div class="col-md-6">
<div class="row">
<div class="col-md-4">
@Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label" })
</div>
<div class="col-md-8">
@Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
</div>
</div>
</div>
<div class="col-md-6">
<div class="row">
<div class="col-md-4">
@Html.LabelFor(model => model.LastName, htmlAttributes: new { @class = "control-label" })
</div>
<div class="col-md-8">
@Html.EditorFor(model => model.LastName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.ParcaliAlisIzinGostergesi, "", new { @class = "text-danger" })
</div>
</div>
</div>
</div><br />
//I have a table,for AdressOne and AdressTwo,I can enter data dynamically int he view
<table id="tableSendInformation" class="table" cellpadding="0" cellspacing="0">
<thead>
<tr>Send Information Detail</tr>
<tr>
<th style="width:150px">AdressOne</th>
<th style="width:250px">AdressTwo</th>
<th></th>
</tr>
</thead>
<tbody></tbody>
<tfoot>
@{
for (int i = 0; i < Model.ListSend.Count; i++)
{
<tr>
<td>
@Html.EditorFor(l => l.ListSend [i].AdressOne)
</td>
<td>
@Html.EditorFor(l => l.ListSend [i].AdressTwo)
</td>
</tr>
}
}
</tfoot>
</table>
//my buttons;
<div class="float-right"> // my button(for AdressOne and AdressTwo)
<div class="col-md-offset-8">
<input type="button" value="Add" class="btn btn-primary" name="Add" id="Add"/>
</div>
</div>
<div class="col-md-offset-8"> //my submit button
<input type="submit" value="Save" id="buttonSave" class="btn btn-primary" name="buttonSave" />
</div>
Я хочу Name, LastName, AdressOne, AdressTwo (несколько записей)данные, когда вы нажимаете кнопку (submit buton => buttonSave), вся эта информация отправляется из представления в контроллер (я хочу отправить одновременно).
Я хочу отправить мои данные и список вмодель с одним постом. Как я могу это сделать?