Asp.net mvc - HttpPost动作开始于任何帖子

时间:2022-12-01 08:20:43

I have two actions in the same name (the normal LongTailSearchBox is showing drop list of the categories, and the HttpPost make the search page (if not exists) and the\n redirect to the search page

我有两个同名的动作(正常的LongTailSearchBox显示类别的下拉列表,HttpPost创建搜索页面(如果不存在)和\ n重定向到搜索页面

 public ActionResult LongTailSearchBox()
            {
 return View();
}

And the httpPost of the action

和httpPost的动作

[HttpPost]
         public ActionResult LongTailSearchBox(string cat1, string cat2, string cat3, string cat4)
         {
return RedirectToAction("LongTailSearchResult", "LongTailSearch", new { name = _url });
    }

when I click on the login button (another form) it's return http post of-course..

当我点击登录按钮(另一种形式)时,它会返回当然的http帖子。

so the HttpPost LongTailSearchBox is start too when the page is loading (I want it to start only if the someone click on the button of the Search and not any button that make httpPost..)

因此,当页面加载时,HttpPost LongTailSearchBox也会启动(我希望它只在有人点击搜索按钮时启动而不是任何创建httpPost的按钮...)

how to do it??

怎么做??

Update:

更新:

when I change the name of one of those actions is work like a charm, but I want them in the same name

当我改变其中一个动作的名称就像魅力一样,但我希望它们具有相同的名称

and the login forsm of the html are <form method="post" action="/LongTailSearch/LongTailSearchBox" novalidate="novalidate">

并且html的登录forsm是

and

<form method="post" action="/login" novalidate="novalidate">

1 个解决方案

#1


1  

You could use ActionMethodSelectorAttribute to select the action depending on the name of the button which caused the post, as explained here: http://www.dotnetcurry.com/ShowArticle.aspx?ID=724

您可以使用ActionMethodSelectorAttribute来选择操作,具体取决于导致帖子的按钮的名称,如下所述:http://www.dotnetcurry.com/ShowArticle.aspx?ID = 724

#1


1  

You could use ActionMethodSelectorAttribute to select the action depending on the name of the button which caused the post, as explained here: http://www.dotnetcurry.com/ShowArticle.aspx?ID=724

您可以使用ActionMethodSelectorAttribute来选择操作,具体取决于导致帖子的按钮的名称,如下所述:http://www.dotnetcurry.com/ShowArticle.aspx?ID = 724