ASP.NET MVC, strongly typed views, partial view parameters glitch

后端 未结 4 883
花落未央
花落未央 2020-12-05 23:48

If i got view which inherits from:

System.Web.Mvc.ViewPage

Where Foo has a property Bar with a type string
And view wants

4条回答
  •  我在风中等你
    2020-12-06 00:24

    Look at ASP.NET MVC source (HtmlHelper.cs -> RenderPartialInternal method -> line 258):

    ...
    
    if (model == null) {
        if (viewData == null) {
            newViewData = new ViewDataDictionary(ViewData);
        }
    
    ...
    

    this is exactly your case. ASP.NET MVC uses the ViewData from your ViewContext

    UPDATED:

    Try this instead:

    <% Html.RenderPartial("_Bar", Model.Bar ?? "Default" ); %>
    

提交回复
热议问题