Hello,
I have a model and each model derives from a base class, that stores a list of translations.
public abstract class BaseObject
{
public List<LocalizationPart> Translations { get; set; }
}
public class LocalizationPart
{
public string Culture { get; set; }
public List<Translation> Translations { get; set; }
}
public class Translation
{
public string Property { get; set; }
public string Text { get; set; }
}
public class CivilStatus : BaseObject
{
public string Name { get; set; }
public string Description { get; set; }
}
this Translations list gets filled during the get or create of an object.
Now I have an edit screen and from this translations list, I get the translations that I need. (Example: on the object CivilStatus, I can have a name and description property, so each property can have a translation per language.) So in the create and edit page I list the appropriate edit fields below the
@Html.Label(...)
.
<div class="editor-label">
@Html.Label(T(property.Name.
</div>
<div class="editor-field">
@if (Attribute.IsDefined(property, typeof(LocalizableAttribute)))
{
foreach (var translation in Model.Translations)
{
@Html.Label(translation.Culture, new {@class = "vt-cultureid"})
var translation = translation.Translations.SingleOrDefault(t => t.Property == property.Name);
if (contentItemVersionRecord != null)
{
@Html.EditorFor(m => contentItemVersionRecord.Translation)<br />
}
}
}
</div>
But when I press the save button, the translations list is null when I look at it in the HttpPost action.
[HttpPost]
public ActionResult Create(CivilStatus civilstatus) { ... }
How can I make it that the translations are bound to the model?