asp.net-mvc2 - Strongly typed helpers not using Model?

后端 未结 1 1744
Happy的楠姐
Happy的楠姐 2020-12-22 02:32

When using strongly typed helpers in MVC2 the input field values aren\'t taken from the Model property when a post is made. Is this default behavior?

(strong

相关标签:
1条回答
  • 2020-12-22 03:09

    When using strongly typed helpers in MVC2 the input field values aren't taken from the Model property when a post is made. Is this default behavior?

    Yes, they are first taken from the ModelState and then from the Model. If you intend to perform some modifications on the model in your POST action you need to remove them from the ModelState first. For example:

    [HttpPost]
    public ActionResult Edit(Product p)
    {
        ModelState.Remove("Name");
        p.Name = "prrrrrrd 2";
        return View(p);
    }
    
    0 讨论(0)
提交回复
热议问题