如何將參數傳遞給html partial並檢索部分html內的值?將參數傳遞給html部分,並檢索部分html內的值
@Html.Partial(MVC.Cans.Shared.Views.CanViewModels, Model, UserExists);
UserExists是邏輯其中部分和我不想改變我的viewmodels這個任務。
你會如何解決這個問題?
如何將參數傳遞給html partial並檢索部分html內的值?將參數傳遞給html部分,並檢索部分html內的值
@Html.Partial(MVC.Cans.Shared.Views.CanViewModels, Model, UserExists);
UserExists是邏輯其中部分和我不想改變我的viewmodels這個任務。
你會如何解決這個問題?
您可以使用@Html.Partial
的第三個參數來傳遞附加視圖數據部分
@Html.RenderPartial("yourPartialName", yourModel, new ViewDataDictionary { { "userExists", true} });
中部分可以使用訪問
@ViewData["userExists"];
工作正常!謝謝斯蒂芬! – Elisabeth
的清潔方法是改變模型,以包括第二值,但如果你不想這樣做,我說你使用的RenderPartial方法,在一個視圖數據字典類型需要:
Html.RenderPartial(
"partialview",
Model,
new ViewDataDictionary { { "UserExists", UserExists} }
);
你想傳遞一個模型加上一些額外的信息的部分,訪問模型和額外的信息? –