私のメインページで(それindex.aspxを呼び出します)私は電話 します
<%Html.RenderPartial("_PowerSearch", ViewData.Model);%>
ここviewdata.model != null
で、パーシャルに到達したとき:
<%=ViewData.Model%>
言うviewdata.model == null
何が得られる?!
私のメインページで(それindex.aspxを呼び出します)私は電話 します
<%Html.RenderPartial("_PowerSearch", ViewData.Model);%>
ここviewdata.model != null
で、パーシャルに到達したとき:
<%=ViewData.Model%>
言うviewdata.model == null
何が得られる?!
ViewData.Model の代わりに ViewData を渡してみましたか? これは、私がヘルパーで使用しているものの要約版です (恥知らずに Storefront シリーズから盗みました)。
/// <summary>
/// Renders a LoggingWeb user control.
/// </summary>
/// <param name="helper">Helper to extend.</param>
/// <param name="control">Type of control.</param>
/// <param name="data">ViewData to pass in.</param>
public static void RenderLoggingControl(this System.Web.Mvc.HtmlHelper helper, LoggingControls control, object data)
{
string controlName = string.Format("{0}.ascx", control);
string controlPath = string.Format("~/Controls/{0}", controlName);
string absControlPath = VirtualPathUtility.ToAbsolute(controlPath);
if (data == null)
{
helper.RenderPartial(absControlPath, helper.ViewContext.ViewData);
}
else
{
helper.RenderPartial(absControlPath, data, helper.ViewContext.ViewData);
}
}
Model ではなく、現在の ViewData を渡すことに注意してください。
これはテストされていません:
<%=Html.RenderPartial("_ColorList.ascx", new ViewDataDictionary(ViewData.Model.Colors));%>
この場合、コントロール ビューはそれに固有のビュー データを期待しています。コントロールが Colors というモデルのプロパティを必要とする場合、おそらく次のようになります。
<%=Html.RenderPartial("_ColorList.ascx", new ViewDataDictionary(new { Colors = ViewData.Model.Colors }));%>