I have the following html.beginform. I want to make all of editorfor statement in foreach. Can someone help me? I use a ViewData.ModelMetadata.Properties, but the Save is out of function.
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Test mit DbFunction</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.ANLAGEID, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ANLAGEID, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.ANLAGEID, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.ANLAGENAME, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ANLAGENAME, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.ANLAGENAME, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.ANLAGEART, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ANLAGEART, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.ANLAGEART, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.ANLAGENUMMER, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ANLAGENUMMER, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.ANLAGENUMMER, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Speichern" class="btn btn-default" />
</div>
I use too foreach loop, but this is not working. It is possible to use a @for loop to solve me problem? If yes, can anyone explain how. Hier ist the foreach
@foreach (var property in ViewData.ModelMetadata.Properties)
{
<div class="editor-line">
<label>@(property.DisplayName ?? property.PropertyName)</label>
@Html.Editor(property.PropertyName)
</div>
}