I have a Create/Update Irrf
view:
@using (Html.BeginForm("Update", "ParamsController", FormMethod.Post))
{
<div class="row">
@Html.DropDownList("Year", Model.Years.Select(p => new SelectListItem { Value = p.ToString(), Text = p.ToString() }), new { @class = "form-control", name = "Ano", id = "AnosDropDown" })
@Html.ValidationMessageFor(n => n.Years)
</div>
<hr/>
<div id="irrContent">
@Html.Partial("_Irrf", Model.List.ToList())
</div>
<button class="col-xs-12 btn btn-success" data-enviaform>Save</button>
}
In the ParamsController
:
public ActionResult Irrf(int? year)
{
if (!year.HasValue)
year= DateTime.Now.Year;
var model = new IrrfViewModel
{
IrrfList = _service.Get(year.Value),
Years = _service.GetYears(),
Year = year.Value
};
if(Request.IsAjaxRequest())
return PartialView("_Irrf", model.IrrfList.ToList());
return View(model);
}
In the _Irrf PartialView:
@model List<Application.IrrfDTO>
@for (var i = 0; i < Model.Count(); i++)
{
<div class="mb20 col-xs-12 col-sm-4">
@Html.TextBoxFor(n => Model[i].FinalValue, new { @class = "form-contro" })
</div>
}
And in the Post Action:
public ActionResult Update(IrrfViewModel model)
{
//Code
}
The IrrfViewModel
:
public class IrrfViewModel
{
public IEnumerable<IrrfDTO> IrrfList { get; set; }
public IEnumerable<int> Years { get; set; }
public int Year { get; set; }
}
I dont know how do i bind the property IrrfList inside of the IrrfViewModel
.
Any Suggestions?