Html.TextBoxFor does not show updated value in POST action

前端 未结 4 2146
不思量自难忘°
不思量自难忘° 2021-02-13 21:12

In my view I have

      <%:Html.LabelFor(model => model.IPAddress)%>

    
<%:Html.TextBoxFor(model => m
4条回答
  •  执笔经年
    2021-02-13 21:30

    Instead of using model binding, id suggest using a tryupdate call.

    [HttpPost]
    public ActionResult Manipulation(FormCollection formCollection)
    {
      MyModel model = new MyModel();
    
      if(TryUpdate(Model))
      {
          enter code here
      }
    
      if(somthing)
      model.IPAddress="100.100.100.100";
      return View(model);
    }
    

    Check out my answer to another post for the general structure i use. Its never failed me before and i believe it covers all bases when updating models from user input.

    asp.net mvc controller post best practices

提交回复
热议问题