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

后端 未结 4 889
花落未央
花落未央 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:37

    If you pass null as the model to RenderPartial, then it will look at the original model, which is why the error says foo.

    You'll need to make sure that bar is initialized to be an empty string instead of null.

    Edit: @Arnis, look at the source code. It doesn't lie. You are passing null to the overload of RenderPartial. You are not passing Foo. Internally, the system uses the Model from your page's ViewContext (which is Foo) when you pass a null Bar to RenderPartial.

提交回复
热议问题