TextBoxFor value not updating after post

后端 未结 5 736
暗喜
暗喜 2021-02-05 11:00

I have a simple strongly typed view, but I cant seem to update a textbox on my form after a post.

Here is my model:

public class Repair
  {
    public          


        
5条回答
  •  执笔经年
    2021-02-05 11:22

    Try this. You can put it in a base controller if you want. It's working well for me. It makes it so unobtrusive validation still works, yet values from the model show through properly as EXPECTED.

    public class BaseController : Controller
    {
        public override void OnActionExecuted(ActionExecutedContext context)
        {
            ModelState.ToList().Select(x => x.Value).ToList().ForEach(x => { x.AttemptedValue = null; x.RawValue = null; });
    
            // Do a bunch of stuff here if needed. Stuff like validation.
            base.OnActionExecuted(context);
        }
    }
    

提交回复
热议问题