How to set value in @Html.TextBoxFor in Razor syntax?

viki picture viki · Dec 21, 2012 · Viewed 128.4k times · Source

I have created an text-box using Razor and trying to set value as follows.

@Html.TextBoxFor(model => model.Destination, new { id = "txtPlace", value= "3" })

I have tried appending value with @

@Html.TextBoxFor(model=> model.Destination, new { id = "txtPlace", @value= "3" })

even though it renders html input tag with empty value

<input id="txtPlace" name="Destination" type="text" value 
   class="ui-input-text ui-body-c ui-corner-all ui-shadow-inset ui-mini" >

What am doing wrong?

Answer

Gaz Winter picture Gaz Winter · Dec 21, 2012

The problem is that you are using a lower case v.

You need to set it to Value and it should fix your issue:

@Html.TextBoxFor(model => model.Destination, new { id = "txtPlace", Value= "3" })