简体   繁体   English

Razor Pages 的部分标签助手中的“for”和“model”之间的主要区别是什么?

[英]What is the main difference between "for" and "model" in a partial tag helper in Razor Pages?

I'm learning Razor Pages Tag Helpers and trying to understand how the partial tag helper works.我正在学习 Razor Pages 标签助手并试图了解部分标签助手的工作原理。 I notice it can take two different attribute to pass data into a partial: for and model .我注意到它可以采用两个不同的属性将数据传递到部分: formodel

for : "The for attribute assigns a ModelExpression to be evaluated against the current model. " for : "for 属性分配一个 ModelExpression 以根据当前模型进行评估。"

model : "The model attribute assigns a model instance to pass to the partial view." model :“模型属性分配一个模型实例以传递给局部视图。”

I'm having trouble understanding this difference.我无法理解这种差异。 Is model simply expecting an instance of the model, where for expects a property?模型是否只是期望模型的一个实例,而for期望一个属性? Can anyone break this down a little more for me?谁能为我再分解一下?

I believe you would use the 'model' instead of a 'for' if you wanted to instantiate a specific model.如果您想实例化特定模型,我相信您会使用“模型”而不是“for”。 The docs explain that using 'for' will infer the model that you want to use.文档解释说使用“for”将推断出您要使用的模型。

Put another way: the model helper will allow you to use a more specific model instead of the inferred one that 'for' provides.换句话说:模型助手将允许您使用更具体的模型,而不是“for”提供的推断模型。

This website is an excellent resource for learning razor pages: https://www.learnrazorpages.com/razor-pages/tag-helpers/partial-tag-helper该网站是学习剃须刀页面的绝佳资源: https ://www.learnrazorpages.com/razor-pages/tag-helpers/partial-tag-helper

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM