asp.net mvc的4×按钮从控制器调用方法 [英] asp.net mvc 4 calling method from controller by button

查看:930
本文介绍了asp.net mvc的4×按钮从控制器调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的控制器我有一流的AccountController和内我有这个方法

In my Controllers i have class AccountController and within in i have this method

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult LogOff()
{
    WebSecurity.Logout();
    return RedirectToAction("Index", "Home");
}

在我的意见我有身体CSHTML页,code,这部分

In my Views i have cshtml page with body and this part of code

<form class="float_left" action="Controllers/AccountController" method="post">
    <button class="btn btn-inverse" title="Log out" type="submit">Log   Off</button>
</form>

这是不行的,谁知道是什么问题或其他一些简单的解决方案?

And this doesn't work, anyone know what is problem or some other simple solution?

推荐答案

你不在这里引用的操作方法:

You're not referencing the action method here:

action="Controllers/AccountController"

对于初学者来说,你不需要指定控制器/ 因为框架会发现控制你。事实上,一个控制器的文件夹的概念是不知道向客户端/ URL /等。你需要给它什么是路线的具体操作方法。

For starters, you don't need to specify Controllers/ because the framework will find the controller for you. Indeed, the notion of a "folder" of controllers isn't known to the client/URL/etc. What you need to give it is a "route" to the specific action method.

由于MVC框架知道在哪里的控制器,你只需要告诉它哪个控制器和操作方法的控制器上:

Since the MVC framework knows where the controllers are, you need only tell it which controller and which action method on that controller:

action="Account/LogOff"

这篇关于asp.net mvc的4×按钮从控制器调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆