0

I am using the mvc Editor features but it seems that the @something doesn't work. I don't know why.

@Html.EditorFor(model => model.Password, new { @Value = "xxx" })

This take the model value and not the "xxx".

Thanks a lot for your help !

MaT
  • 1,556
  • 3
  • 28
  • 64

3 Answers3

5

You don't need the @ in front of Value. As you have it already in front of Html. Remove it and it should work.

Lews Therin
  • 10,907
  • 4
  • 48
  • 72
  • Nop I always have the model value and not the other with `@Html.EditorFor(model => model.Password, new { Value = "xxx" })` – MaT Oct 05 '12 at 08:11
  • The value used is not "xxx" but the model's (user) value. – MaT Oct 05 '12 at 08:14
1

You have to remove the second @. if you want your value to come from model, you have to write something like this,

@Html.EditorFor(model => model.Password, new { value = Model.Password})

In either case you have to remove the second @ before value

Rahul R.
  • 5,965
  • 3
  • 27
  • 38
  • if you want the value of the model to be shown you dont need the new { value = Model.Password}. @Html.EditorFor(model => model.Password) should be enough – middelpat Oct 05 '12 at 09:11
  • That would be correct. But the use of value would just be unnecessary. i agree the use of 'htmlattributes' does come in handy for other attributes – middelpat Oct 05 '12 at 10:26
0

The @Value works for TextBoxFor but not EditorFor (since it is generic...).

Samuel Caillerie
  • 8,259
  • 1
  • 27
  • 33