TextBoxFor Helper retains previous value even when model value is empty

前端 未结 3 923
北恋
北恋 2021-01-11 16:54

I have an MVC form for adding a simple entity. I am using TextBoxFor(model => model.FieldName) to create the input fields. I have a Save button and a Save and New button.

3条回答
  •  时光说笑
    2021-01-11 17:48

    I had the same issue see here:

    Updating value provider prior to TryUpdateModel

    However - after a post - if it is successful, you should by design be redirecting to a GET action for your next data. This is part of the PRG (post-redirect-get) pattern that is meant to be used by mvc. The helpers assume you are using this pattern and if you are displaying information after a post, there mustve been an error so they redisplay the posted values for "correcting". Try not to work around this - but refactor your code to properly work with PRG.

提交回复
热议问题