Problem understanding Model Binding

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 years ago
Hi all,

I am new to MVC and I have a problems understanding model binding.

I need to edit Header.cshtml to customize my theme. This page makes a call to HeaderLinks and passes a model(?) like this:

@Html.Action("HeaderLinks", "Common");

My Questions:

1- Is that line really passing the "Common" model?
2- If yes, where is Header.cshtml getting that model from in order to pass it?


Also, HeaderLinks.cshtml makes the following call:
@if(Model.IsAuthenticated)

1- How can I make that same call on Header.cshtml?
2- How can I get a hold of the necesary model in order to make that call?

I hope somebody can help me make some sense of all this.

Best regards!
11 years ago
LAM-ECOM wrote:


@Html.Action("HeaderLinks", "Common");

1- Is that line really passing the "Common" model?


No, it's calling the Method HeaderLinks on the Common controller.
11 years ago
keesjan wrote:


@Html.Action("HeaderLinks", "Common");

1- Is that line really passing the "Common" model?


No, it's calling the Method HeaderLinks on the Common controller.


Hi keesjan,

Thanks for your answer. It definitely makes more sense the way you described.

Now, going back to my second question. How can I make a call to see if user is authenticated?

Thanks again.
11 years ago

        @if(User.Identity.IsAuthenticated)
        {
            
        }
11 years ago
LAM-ECOM wrote:


@Html.Action("HeaderLinks", "Common");

1- Is that line really passing the "Common" model?


No, it's calling the Method HeaderLinks on the Common controller.

Hi keesjan,

Thanks for your answer. It definitely makes more sense the way you described.

Now, going back to my second question. How can I make a call to see if user is authenticated?

Thanks again.


This is how I got around it: @if(Request.IsAuthenticated).

Now, what would be the difference between these two calls? and Why they did not use Request.IsAuthenticated?

@if(Request.IsAuthenticated)
@if(Model.IsAuthenticated)

Thanks again.
11 years ago
User.Identity.IsAuthenticated is the same as Request.IsAuthenticated
Don't know why they added the IsAuthenticated property to the viewmodel
but my guess is because it looks cleaner (eg. only use a viewmodel in a view)
11 years ago
keesjan wrote:
User.Identity.IsAuthenticated is the same as Request.IsAuthenticated
Don't know why they added the IsAuthenticated property to the viewmodel
but my guess is because it looks cleaner (eg. only use a viewmodel in a view)


Thanks a lot!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.