Я использую asp.net mvc5, в котором я использую Ienumerable в View, а также в Controller для передачи множественных значений, для которых мне нужно использовать цикл Foreach.После использования всего этого я получаю значения NULL в контроллере от модели
Для контроллера:
public ActionResult ManageTimeExpense(IEnumerable<TimeExpense> Timemodel, IEnumerable<ExpenseBook> Expensemodel)
{
var get = Request.Files.Count;
try
{
{
//for(var i = Timemodel)
foreach(var r in Timemodel)
для просмотра:
@model IEnumerable<Tuple<TimeSheet.Models.TimeExpense , TimeSheet.Models.ExpenseBook>>
@{
Layout = null;
}
@using (Html.BeginForm("ManageTimeExpense", "TimeExpense", FormMethod.Post,new { enctype = "multipart/form-data" }))
{ <div class="col-lg-3 col-md-3 col-sm-12 col-xs-12">
<label>Hours:</label>
<input id="Hours" name="Hours" type="number" class="form-control hours" placeholder="24 Hours" />
@* @Html.TextBoxFor(h => h.Hours, new {@type="number",@class = "form-control",@placeholder="24 Hours", Required = "required" })*@
</div>
<div class="col-md-3 col-sm-12 col-xs-12">
<label></label>
<input type="submit" value="Save" class="form-control btn btn-primary">
</div>
$("#Save").click(function () {
var TimeExpense = [];
var ExpenseBook = [];
var Date = $("#Date").val();
var TimeExpenseMasterId = $("#TimeExpenseMasterId").val();
$('.invoicerow1').each(function () {
var TaskMasterId = $(this).closest('tr').find('.task').val();
var Hours = $(this).closest('tr').find('.hours').val();
var TimeDescription = $(this).closest('tr').find('. timedes').val();
TimeExpense.push({
TimeExpenseMasterId: TimeExpenseMasterId,
Date: Date,
TaskMasterId: TaskMasterId,
Hours: Hours,
TimeDescription: TimeDescription,
});
});
$('.invoicerow').each(function () {
var ExpenseDescription = $(this).closest('tr').find('.exp').val();
var Amount = $(this).closest('tr').find('.amt').val();
var Currency = $(this).closest('tr').find('.currency').val();
var BillStatus = $(this).closest('tr').find('.bill').val();
ExpenseBook.push({
ExpenseDescription: ExpenseDescription,
Amount: Amount,
Currency: Currency,
BillStatus: BillStatus,
});
});
var data = {
TimeExpense: TimeExpense,
ExpenseBook: ExpenseBook
};
});
</script>