0
我想知道UpdateModel()方法的工作原理。我只知道它是爲了更新當前的模型數據。但它是如何工作的?因爲當我在編輯控制器方法中使用UpdateModel()時,有文件上傳的功能。我保持上傳文件的路徑在我的數據庫。但在執行後,路徑的UpdateModel方法值將替換爲「System.Web.HttpPostedFileWrapper」。爲什麼會這樣發生的: 代碼:UpdateModel方法如何在asp.net mvc中工作2
if (!String.IsNullOrEmpty(Request.Files["TDSCertificatePath"].FileName))
{
TrustTrusteeMapping objTrustTrusteeMapping = trust_trustee_mapping_management.GetTrustTrusteeMappingById(objTDSDetail.TrustTrusteeMappingId);
string TrustTrusteeMappingName = objTrustTrusteeMapping.Trust.TrustName + "_" + objTrustTrusteeMapping.TrusteeMaster.FullName;
HttpPostedFileBase fileToUpload = Request.Files["TDSCertificatePath"];
objTDSDetail.TDSCertificatePath = CommonFunctions.UploadFile("TDSCertificatePath", "Content\\TDSCertificate\\", TrustTrusteeMappingName, fileToUpload);
fileToUpload = null;
objTrustTrusteeMapping = null;
}
UpdateModel(objTDSDetail);//After executes this the value of objTDSDetail.TDSCertificatePath changes as I said before.
你爲什麼不搶MVC源,和調試自己呢?或者,如果你不能打擾,你可以看看它在這裏:http://aspnet.codeplex.com/sourcecontrol/changeset/view/23011?projectName=aspnet#266451 – RPM1984 2010-10-04 11:39:55
對不起,我試過了,但如何UpdateModel ()工作不會(顯示)內部方法執行。我希望看到。想要了解它的工作方式。 – 2010-10-04 11:50:16
這是因爲'UpdateModel'最後使用了一個接口而不是一個具體的類 - 嘗試查看'DefaultModelBinder.cs'類。 – Buildstarted 2010-10-04 14:11:23