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

有帮助吗?

解决方案

You can use the weakly typed version :

for (i = 1; i <=3; i++) {
    @Html.Editor("property"+i);
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top