Skip to content Skip to sidebar Skip to footer

Asp.net Mvc Html.textbox Refresh Problem

i have a problem with asp.net mvc 2 and the html.textboxfor helper. i use the follow code in a form: <%= Html.TextBoxFor(model => model.Zip, new { @class = 'txt', id = 'zip',

Solution 1:

You cannot modify the values in your controller action because the helper will always use the POSTed values when generating the textbox. This is by design and if you want to workaround it you will have to write your own helper or generate the textbox manually:

<inputtype="text" 
    name="Zip" 
    value="<%= Html.Encode(Model.Zip) %>"class="txt"id="zip" 
    tabindex="1" 
/>

Solution 2:

Clear the modelstate using ModelState.Clear(), update your object and then return it.

Post a Comment for "Asp.net Mvc Html.textbox Refresh Problem"