简体   繁体   中英

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. I notice it can take two different attribute to pass data into a partial: for and model .

for : "The for attribute assigns a ModelExpression to be evaluated against the current model. "

model : "The model attribute assigns a model instance to pass to the partial view."

I'm having trouble understanding this difference. Is model simply expecting an instance of the model, where for expects a property? 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. The docs explain that using 'for' will infer the model that you want to use.

Put another way: the model helper will allow you to use a more specific model instead of the inferred one that 'for' provides.

This website is an excellent resource for learning razor pages: https://www.learnrazorpages.com/razor-pages/tag-helpers/partial-tag-helper

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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