ho attaccato su questo tema per un po '..ASP.NET MVC 5 modello elenco vincolante è vuoto
ho creato un semplice modello di vista:
public class AddTranslationViewModel
{
public List<ProjectTranslation> ProjectTranslations { get; set; }
public AddTranslationViewModel()
{
ProjectTranslations = new List<ProjectTranslation>();
}
}
classe ProjectTranslation:
public class ProjectTranslation
{
public int ProjectTranslationId { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string Address { get; set; }
public int LanguageId { get; set; }
public Language Language { get; set; }
public int ProjectId { get; set; }
public Project Project { get; set; }
}
Una vista semplice che utilizza l'AddTranslationViewModel
<table class="table">
@foreach (var item in Model.ProjectTranslations)
{
@Html.HiddenFor(modelItem => item.ProjectTranslationId)
<tr>
<td>
@Html.DisplayFor(modelItem => item.Language.LanguageCode)
</td>
<td>
@Html.EditorFor(modelItem => item.Title)
</td>
</tr>
}
</table>
<input type="submit" value="Send" />
e, infine, il mio metodo POST:
public ViewResult AddTranslation(AddTranslationViewModel projectTranslations)
{
if (ModelState.IsValid)
{
//...
}
return View(projectTranslations);
}
L'idea è molto semplice, voglio mostrare un elenco di elementi dove dovrebbe essere possibile cambiare/modificare i valori.
Tuttavia, il collegamento del modello non funziona, il parametro projectsTranslations nel metodo HTTPPost AddTranslation è sempre vuoto.
Qual è l'errore qui?
assicurarsi che si sta postando questa pagina utilizzando un
Ho provato un po 'di tutto, al momento è: @using (Html.BeginForm()) – mitti
il nome dei metodi Get e Post Action è lo stesso? e conferma se hai usato [HttpPost] sul tuo metodo post azione – adeel41