Question

I am new to ASPNET MVC. I have searched many hours but couldn't find a way to solve my simple problem.

For a Model with properties like "property1" "property2" "property3", I want to simplify the code in a View to something like:

for (i = 1; i <=3; i++) {
    @Html.EditorFor(model=>model.["property"+i];
}

How to replace the expression with custom names?

Thanks a lot

Was it helpful?

Solution

You can use the weakly typed version :

for (i = 1; i <=3; i++) {
    @Html.Editor("property"+i);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top