2011-10-05 44 views
1

我在.cshtml中有這段代碼。使用MVC3 @使用顯示控件

@using (Html.BeginRouteForm("CheckoutShippingAddress", FormMethod.Post)) 
{ 
<div class="enter-address-body"> 
@{ 
var dataDictPatient = new ViewDataDictionary(); 
dataDictPatient.ModelState.Merge(ViewData.ModelState); 
dataDictPatient.TemplateInfo.HtmlFieldPrefix = "PatientInformation"; 
    @Html.Partial("_CreateOrUpdateAddress", Model.PatientRoom, dataDictAddress)    
    } 

正在發生的事情是錯誤的

The model item passed into the dictionary is of type 'Models.Common.PatientModel', but this dictionary requires a model item of type 'Models.Common.AddressModel'.

什麼,我不知道是我改變了字典想patientmodel而不是addressmodel。

+1

您發佈的代碼與錯誤沒有任何關係,錯誤是由頁面頂部的@model語句導致的 –

+0

同意,您在那裏工作正常 - 但您需要更改模型聲明 – Cody

+0

您能否顯示您的操作方法和模型? – shuniar

回答

0

你需要確保你的模型的PatientRoom屬性被聲明爲PatientModel(例如,你不只是改變PatientRoom但離開類型爲AddressModel,並且也是在@model聲明您的_CreateOrUpdateAddress模型的頂部是@model PatientModel