ASP.Net MVC 2 - Need To Add A Default Property To A Strongly Typed Html.Textbox Helper In Asp.Net MV

Posted by Sara on Stack Overflow See other posts from Stack Overflow or by Sara
Published on 2010-04-22T21:25:29Z Indexed on 2010/04/22 22:43 UTC
Read the original article Hit count: 798

I'm having a problem with something that I'm sure is very simple. I have been using Asp.Net MVC and I decided to start using Asp.Net MVC 2. Something has changed and now I need a little help. The strongly typed helpers are now written like this -

<%= Html.TextBoxFor(model => model.State) %>

I need to add a default value to a textbox. In the prior version of Asp.Net MVC it was easy to assign a default value. I thought doing the following would work in MVC 2-

<%= Html.TextBoxFor(model => model.CountyId, new{ value = 840 })%>

This, however, does not work for me in Asp.Net MVC 2. The value is still blank for the textbox. I want to make sure that this isn't some random error that I am having. Has anyone else encountered the same problem? I have searched and searched to find more information on the default property for the html helpers in MVC 2, but I can't find anything. Does anyone out there know how to correctly assign a default value to a textbox in Asp.Net MVC 2?

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about mvc2