how to get an id of a model in a view via a link?

Asked

Viewed 86 times

1

I have a link that calls a function JS (POPUP), in this popup I have a registration FORM, to validate all parameters of my form, I need to get the ID of My Model that is in the Link view I am not able to get this ID to insert data in the BD

Take a look at my Cod:

view:

<table>
<tr>
    <th>Nome</th>
    <th>Adicionar</th>
</tr>
@foreach (var c in Model.Contactados)
{
 <tr>
   <td>@Html.DisplayFor(cc => c.Nome)</td>
     <td><a class ="chamar" href="#">Adicionar</a></td>        
 </tr>
}

form that should receive the ID of the previous view:

   @using Forte.Rastreador.ViewModels
@model SuperViewModel
@using (Html.BeginForm("CadastrarContatoContactado", "Master", FormMethod.Post))
{

@Html.ValidationSummary(false)

<fieldset>
<legend></legend>
@Html.Label("Contato: ")
@Html.TextBoxFor(c=>c.DescricaoContatoContactado)
@Html.Label("Tipo Contato: ")
@Html.DropDownListFor(c => c.CodTipoContato, Model.TipoContatoList)

<input type="submit" value="Adicionar Contato" />

}
  • Dude, it’s a little confusing. Explain it better ? You want to get this ID on the link after it was registered ?

  • yes that’s right, I’m not getting the id of the registered model.

  • 1

    Dude, try rephrasing your question.

  • @Hansmiller Question solved? Consider marking an answer as accepted. How and why to accept an answer?

1 answer

1

Use @Html.HiddenFor(c=>c.Id) inside the Form. So it will be sent to the Controller.

Browser other questions tagged

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