Doubt with mvc helpers

Asked

Viewed 81 times

1

I have this include in my view(cshtml)

@model List<SuporteTecnico.Models.T_PDV>

Now I need to create a table, and in a TD I put the label and in another the Textbox. I did so:

<tr>
 <td>@Html.Label("Razão Social")</td>
 <td>@Html.TextBoxFor(r => r.)</td>//Aqui não consigo pegar a RazaoSocial
</tr>

I tried Model => Model.... and also nothing came, changed to model => model... and nothing either.

What I really need is to create an id for the textbox, because I work with dynamic values coming from a jquery function.

In Intellisense I bring: Select<>, Removeat,Add, Addrange, Agregate<>, All<>, Any<> and etc...

2 answers

2


It would be something like:

@if (Model != null && Model.Count > 0)
{
    <tr>
        <td>@Html.Label(r => r[0].RazaoSocial)</td>
        <td>@Html.TextBoxFor(r => r[0].RazaoSocial)</td>
    </tr>
}

To assemble a sequence of the fields, it would be something like:

@if (Model != null && Model.Count > 0)
{
    @for (var i=0; i < Model.Count; i++)
    {
        <tr>
            <td>@Html.Label(r => r[i].RazaoSocial)</td>
            <td>@Html.TextBoxFor(r => r[i].RazaoSocial)</td>
        </tr>
    }
}
  • I didn’t realize it was a list.

-1

I think it works:

@foreach (var item in @Model)
{
  <tr>
      <td>@Html.Label("Razão Social")</td>
      <td>@Html.TextBox(Model.RazaoSocial)</td>
  </tr>
} 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.