Wsadziłem w tej kwestii na chwilę ..ASP.NET MVC lista wiążący 5 model jest pusty
stworzyłem prosty model wyświetlania:
public class AddTranslationViewModel
{
public List<ProjectTranslation> ProjectTranslations { get; set; }
public AddTranslationViewModel()
{
ProjectTranslations = new List<ProjectTranslation>();
}
}
klasa 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; }
}
prosty widok, który wykorzystuje 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" />
i wreszcie moja metoda POST:
public ViewResult AddTranslation(AddTranslationViewModel projectTranslations)
{
if (ModelState.IsValid)
{
//...
}
return View(projectTranslations);
}
Pomysł jest bardzo prosty, chcę pokazać listę elementów, w których powinno być możliwe, aby zmienić/edytować wartości.
Jednak powiązanie modelu nie działa, parametr projectsTranslations w metodzie HTTPPost AddTranslation jest zawsze pusty.
Co to za błąd?
upewnić Piszesz do tej strony za pomocą
Próbowałem wszystkiego, w tej chwili: @using (Html.BeginForm()) – mitti
to jest nazwa metod Get i Post Action jest taka sama? i sprawdź, czy użyłeś [HttpPost] w swojej metodzie post-działania. – adeel41