Doubt with mvc helpers

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 did not come anything, I changed to model = > model ... and nothing too.

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

No IntelliSense I bring: Select , RemoveAt, Add, AddRange, Aggregate

asked by anonymous 15.05.2014 / 15:53

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 build a sequence of fields, it would look 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>
    }
}
    
15.05.2014 / 15:59
-1

I think this works:

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