公共操作方法'..'没有控制器找到“..” [英] A public action method '..' was not found on controller '..'

查看:1488
本文介绍了公共操作方法'..'没有控制器找到“..”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想把一个随机图像在我的MVC项目的每一个的ViewPage。所以我创建了一个返回partialView并调用共享的布局页面的方法的方法。

I wanted to put a random image on every viewpage of my mvc project. So i created a method that returns a partialView and call that method in the shared Layout page.

当我尝试用正确的用户名和密码登录这工作得很好。所使用的是loged,每个页面包含一个随机图像。但是,当我把用户名和密码的组合无效。共享的布局页面没有找到我想打电话给我控制器 @ Html.Action 和actualy登录视图应该用一个错误信息的用户名无效组合返回,密码和ofcourse,与随机形象。

This works fine when I try to login with a correct username and password. The used is loged in and every page contains a random image. But when I give the invalid combination of username and password. The shared layout page does not find the controller I want to call with my @Html.Action and actualy the login view should be returned with an error message 'invalid combination of username and password' and ofcourse, with the random image.

的InnerException:

InnerException:

{公共行动方法RandomSponsor没有控制器Project.WebUI.Controllers.HomeController'。找到}

{"A public action method 'RandomSponsor' was not found on controller 'Project.WebUI.Controllers.HomeController'."}

我的共享布局Html.Action。

My Html.Action in shared layout.

@Html.Action("RandomSponsor", "Home")

在HomeController的方法。

Method in homecontroller.

    [HttpGet]   
[ChildActionOnly]
public ActionResult RandomSponsor()
{
    var model = service.getRandomSponsor();
    return PartialView("RandomSponsor", model);
}

该getRandomSponsor法正常工作,这其中始终返回返回到RandomSponsor.cshtml视图中的一个随机字符串值。

The getRandomSponsor method works fine, this one always returns one random string value that is returned to the RandomSponsor.cshtml view.

RandomSponsor.schtml(只包含图像串)

RandomSponsor.schtml (only contains the image string)

<img src="~/Content/Images/Advert/@(Model)" alt="a" />

我寻找这个问题的网站,但没有找到一个解决办法,没有人知道这个问题的答案吗?
也许这与HTTPGET东西HttpPost?

I searched the web for this problem but didn't found a solution, does anyone know the answer to this one? Might it be something with HttpGet of HttpPost?

问候。

推荐答案

如果正在执行的请求是 POST 然后它会试图找到一种方法 RandomSponsor acceptimg HttpPost 。如果是有意义的,你可以删除 HTTPGET 和应该做的伎俩。

If the executing request is a POST then it will try to find a method RandomSponsor acceptimg HttpPost. If make sense, you could remove HttpGet and that should do the trick.

如果你有一个POST开始(我有一个动作返回返回调用的RenderAction的局部视图视图)调用的多层次也会发生这种情况,那么调用的RenderAction仍然会寻找一个POST方法

This can also happen if you have many layers of calls that start with a POST (I had an action returning a view returning a partial view calling RenderAction), then the call to RenderAction will still look for a POST method

这篇关于公共操作方法'..'没有控制器找到“..”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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