I have a class like this
public class Sample_Class {
public string Property1 { get; set;}
public string Property2 { get; set;}
}
and I want to have a html form like this:
<fieldset>
<legend>Change Password Form</legend>
<ol>
<li>
@Html.LabelFor(m => m.Property1)
@Html.TextBoxFor(m => m.Property1)
@Html.ValidationMessageFor(m => m.Property1)
</li>
<li>
@Html.LabelFor(m => m.Property2)
@Html.TextBoxFor(m => m.Property1)
@Html.ValidationMessageFor(m => m.Property1)
</li>
</ol>
<input type="submit" value="Submit" />
</fieldset>
how can I do this dynamically? for example, like this:
....
@foreach (property in Sample_Object.Properties) {
<li>
@Html.LabelFor(property)
@Html.TextBoxFor(property)
@Html.ValidationMessageFor(property)
</li>
}
....
foreachsuch is shown in your above example. Are you wanting to create a partial-view instead?collectionproperty in your class. What it it that you want to achieve?