Is the default scope for Html.BeginForm always the current scope in ASP.NET MVC?

I had the following code snippet in my Razor layout view (which is used by all the views in my application):

@using (Html.BeginForm("Logout", "Account", FormMethod.Post, new { id = ViewIDs.Shared._AuthenticationPartial.LogoutForm })) { 

This worked great with my Home and Account views, i.e. displayed the form that was submitted to ~ / Account / Logout. However, when it is used with a view inside the Person area, it unexpectedly goes to the ~ / Person / Account / Logout folder.

Now I was able to fix it as follows:

 @using (Html.BeginForm("Logout", "Account", new { area = "" }, FormMethod.Post, new { id = ViewIDs.Shared._AuthenticationPartial.LogoutForm })) { 

Is this done correctly, i.e. is the default area the current area? Or am I having a configuration problem in my application?

+7
source share
1 answer

This is the right way. ASP.NET MVC uses the current route values ​​in HTML helpers implicitly. Just like you can leave just by specifying the name of the action when you bind to the action in the same controller. If you are contacting another area, you must specify it as follows.

+3
source

All Articles