ASP.NET MVC 3 Model Id using Route Id value

后端 未结 3 1730
执笔经年
执笔经年 2020-12-20 20:27

Scenario
Route: /template/customize/10 Where: 10 = ID of Template()

In the controller the model is created based on the template so that the Vie

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-20 20:53

    To prevent route values from overriding the model's corresponding properties, call ModelState.Clear() in your controller action. Be careful to call this method after using/reading the model state.

    public ActionResult Customize( int id )
    {
        var template = Persistence.Data.RetrieveObject