tags:

views:

259

answers:

2

By default, a textbox rendered using <%= Html.TextBox("somefield")%> uses the value from the post data, e.g. if you have validation errors on your page, the value is retrieved from the posted data and used for the value attribute.

Now, in a few cases I want to be able to clear that value, in other words I want the textbox to be blank, I don't want MVC to get the value from the posted data and uses it for the value attribute, how can I do? How can I clear the post data?

Thanks

+4  A: 
ModelState.Remove("key");
ChaosPandion
This also seems to work if you want to clear all the values: ModelState.Clear();
jesperlind
+1  A: 

Remove the value from the model state, like this:

ViewData.ModelState.Remove("somefield");
SLaks