.netasp.net-mvcasp.net-mvc-3razorhtml.textboxfor

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


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?


Solution

  • 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" })