What is the main difference between "for" and "model" in a partial tag helper in Razor Pages?
Asked Answered
O

1

7

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?

Overmaster answered 22/1, 2020 at 16:10 Comment(0)
E
3

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

Enschede answered 22/1, 2020 at 16:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.