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

I had the following piece of code in my Razor Layout view (which is shared by all views in my application):

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

This worked fine with my Home and Account views, ie, it rendered a form that posted to ~/Account/Logout. However, when used with a view inside an area called "Person", it suddenly posted to ~/Person/Account/Logout.

Now, I was able to fix this as follows:

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

Is this the right way to do this, ie, is the default area by definition the current area? Or am I having a configuration problem in my application?


It's the right way. ASP.NET MVC uses current route values in HTML helpers implicitly.That's also how you can get away with just stating the action name when you are linking to an action in the same controller. If you are linking to another area, you have to state it like this.

链接地址: http://www.djcxy.com/p/14058.html

上一篇: 如何确定CUDA流阻塞的原因

下一篇: Html.BeginForm的默认区域始终是ASP.NET MVC中的当前区域吗?