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?
This question is related to
.net
asp.net-mvc
asp.net-mvc-3
razor
html.textboxfor
It is going to write the value of your property model.Destination
This is by design. You'll want to populate your Destination property with the value you want in your controller before returning your view.
Tries with following it will definitely work:_x000D_
_x000D_
@Html.TextBoxFor(model => model.Destination, new { id = "txtPlace", Value= "3" })_x000D_
_x000D_
@Html.TextBoxFor(model => model.Destination, new { id = "txtPlace", @Value= "3" })_x000D_
_x000D_
<input id="txtPlace" name="Destination" type="text" value="3" class="ui-input-text ui-body-c ui-corner-all ui-shadow-inset ui-mini" >
_x000D_
This works for me, in MVC5:
@Html.TextBoxFor(m => m.Name, new { @class = "form-control", id = "theID" , @Value="test" })
I tried replacing value
with Value
and it worked out. It has set the value
in input
tag now.
I tried replacing value
with Value
and it worked out. It has set the value
in input
tag now.
@Html.TextBoxFor(model => model.Destination, new { id = "txtPlace", Value= "3" })
Source: Stackoverflow.com