文档资料: https://msdn.microsoft.com/zh-cn/library/ee728634.aspx

 

有很多重载其中

使用来自值提供程序的值更新指定的模型实例。

 if(IsPostBack )
            {
                GuestResponse rsvp = new GuestResponse();
                if (TryUpdateModel(rsvp, new FormValueProvider(ModelBindingExecutionContext)))//更新GuestResponse 对象的属性,
                    //以反映用户在窗体中提交的数据值,然后将GuestResponse对象存储在存储库中
                {
                    ResponseRepository.GetRepository().AddResponse(rsvp);
                    if (rsvp.WillAttend .HasValue &&rsvp .WillAttend .Value )
                    {
                        Response.Redirect("seeyouthere.html");

                    }
                    else
                    {
                        Response.Redirect("sorryyoucantcome.html");

                    }
                }
            }


TryUpdateModel 方法将执行称为模型绑定的过程,在此过程中,将使用来自浏览器请求的数据值填充数据模型对象的属性。TryUpdateModel 方法的另一个参数是ASP.NET用于获取

所需值得对象------System.Web.ModelBinding.FormValueProvider类,它提供来自窗体数据的值。调用TryUpdateModel方法的结果是:更新GuestResponse对象的属性,以反映客户在窗体中提交的数据值,然后将GuestResponse对象存储在存储库中。

《精通asp.net》第一章

相关文章: