문제

내 메인 페이지에서 (전화하십시오 index.aspx) 나는 전화한다

<%Html.RenderPartial("_PowerSearch", ViewData.Model);%>

여기 viewdata.model != null부분에 도착하면 :

<%=ViewData.Model%>

말한다 viewdata.model == null

무엇을 주?!!

도움이 되었습니까?

해결책

ViewData.Model 대신 ViewData를 전달해 보셨습니까? 이것은 내가 헬퍼에서 사용하는 요약 버전입니다 (상점에서 뻔뻔스럽게 도난당한 시리즈) :

    /// <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);
        }
    }

모델이 아닌 현재 ViewData를 전달합니다.

다른 팁

이것은 테스트되지 않았습니다.

<%=Html.RenderPartial("_ColorList.ascx", new ViewDataDictionary(ViewData.Model.Colors));%>

귀하의 제어보기는이 경우에 맞는보기 데이터를 기대하고 있습니다. 컨트롤이 색상이라는 모델에서 속성을 원한다면 아마도 다음과 같습니다.

<%=Html.RenderPartial("_ColorList.ascx", new ViewDataDictionary(new { Colors = ViewData.Model.Colors }));%>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top