Take the 2-minute tour ×

How the @Html.EditorForModel(Model.ElementAt(i)) really works, if "model.count()" is 5. Why do I get a dimension of "5*5" elements?

@model List<model>

The only attempt that actually gave me 5 elements is:

@model List<model>


In the template for model I am using Javascript to change a value of the model.Numbers, using a "GetElementById("NumbersX")":

 @Html.TextBoxFor(m => m.Numbers, new { id = "NumbersX" })

Does anyone know a better way of implementing, or an already implemented function, to perform this task ?

share|improve this question
Have you tried i < Model.Count() - 1? –  Neil Knight Apr 24 '12 at 16:10
Tryed, and get 4rows and 4cols. for some weird reason, the template its printing all elements in model every time. –  user1353547 Apr 24 '12 at 16:26

1 Answer 1

EditorForModel outputs an editor for the whole model.

Your model has five elements, so one "whole editor" is five elements.
You call it five times, so you get 5x5 elements.

You probably meant to call EditorFor, not EditorForModel.

@Html.EditorFor(m => m.ElementAt(i)) 

But that will not work as you expect either. However, because you have a List as your model, you can make it work properly:

@Html.EditorFor(m => m[i]) 

The overload you are calling accepts Object additionalViewData as its parameter. You pass a lambda as if you were calling EditorFor, and that lambda simply does nothing.

share|improve this answer

Your Answer


