[英]How do I pass a property of my razor model to a partial?
I have a razor page, where the SomeList property of my page model is of type List<Blah>
, with the following:我有一个 razor 页面,其中我的页面 model 的 SomeList 属性是
List<Blah>
类型,具有以下内容:
@await Html.PartialAsync("_QueueTable", Model.SomeList)
I have a partial with the following:我有以下部分:
@page
@model List<Blah>
When I hit my breakpoint, trying to access Model gives me a NullReferenceException.当我到达断点时,尝试访问 Model 会给我一个 NullReferenceException。
If I inspect ViewData inside the Non-Public members of the ViewBag I see the Model I'm looking for.如果我检查 ViewBag 的非公共成员中的 ViewData,我会看到我正在寻找的 Model。
How do I set this up properly so that I can simply reference Model in my partial so I can act on my list?如何正确设置它,以便我可以在我的部分中简单地引用 Model 以便我可以对我的列表采取行动?
the problem was that I had an @page directive at the top of my partial问题是我的部分顶部有一个@page 指令
I tried to remove the directive when I created the partial, but VS gave me an error saying that it must be present.我在创建部分时尝试删除该指令,但 VS 给了我一个错误,说它必须存在。
I didn't give it another thought, until a co-worker finally pointed it out.我没有再想它,直到一位同事终于指出了这一点。 I removed the directive, did a clean, did a build and I'm in business.
我删除了指令,进行了清理,进行了构建,然后我就开始营业了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.