3
I need to send to a method in Controller, the values filled in the column Payment_value as shown below:
By clicking the green button, send via post, the values of the list below that generated the table:
@foreach (var item in Model.vmListPagamentos)
{
<tr class="odd gradeX">
<td>@Html.DisplayFor(modelItem => item.Matricula)</td>
<td>@Html.DisplayFor(modelItem => item.Nome)</td>
<td>@Html.DisplayFor(modelItem => item.Empresa_DtEntrada)</td>
<td>@Html.DisplayFor(modelItem => item.Empresa_DtSaida)</td>
<td>@Html.TextBoxFor(modelItem => item.Pagamento_Valor)</td>
<td>@Html.TextBoxFor(modelItem => item.DtPagamento)</td>
</tr>
}
The problem lies in the concatenation of monetary values. Formcollection, when passing the information to the controller, separates the values from the attribute "item.Paymentvalue" with commas. And the value of the field also possessed comma. To make it clearer look at the image below:
I can’t imagine taking these two string values without using Split(','). But if I use the split to break this string in two, it will break into 4. Because I work with monetary value, I don’t want to keep going around concatenating these values. Is there another way to send values to a controller action other than via Formcollection? Why I also tried to send the Model as a parameter and it was not..
Thanks for the feedback, Randrade. I tried to use the schematic you gave me, but I’m running into a mistake. "=> item" is in error in Partialview, displaying the following message: "The name 'item' does not exist in the Current context" It was referenced on the page as you directed. @foreach (var item in Model.vmListPayments) { @Html.Partial("_Payment", item) }
– Gleison França
@Gleisoconfidence Sorry, my fault. Change the
item
forModel
. I changed the answer so you’d have an idea.– Randrade
Thanks to the return Randrade, I was able to display the screen with the filled out list without errors following his scheme. When clicking the button the event is triggered and access the action. However, the Model parameter is null. What did I do wrong? I have a list inside a viewModel that follows this pattern: public List<VW_PAGAMENTOS> vmListPagamentos { get; set; }
– Gleison França