调用的RenderAction错误的操作方法 [英] RenderAction calls wrong action method

查看:135
本文介绍了调用的RenderAction错误的操作方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与挣扎的RenderAction,问题是它调用了错误的操作方法我的控制器。

I'm struggling with renderaction, the problem is that it calls the wrong action method on my controller.

在我的用户控制器有两种操作方法调用的编辑,一个是get和一个POST请求:

On my "Users" controller there are two action methods called edit, one for get and one for post requests:

public virtual ActionResult Edit(int id)
{
 //return a view for editing the user
}


[AcceptVerbs(HttpVerbs.Post)]
public virtual ActionResult Edit(UserViewModel model)
{
 //modify the user...
}

在我看来,我打电话给它的RenderAction如下:

In my view, I'm calling Renderaction it as follows:

Html.RenderAction("Edit", "Users", new { id = 666});

现在的问题是,我想要呈现的GET操作方法。但是(也许是因为该机型还包含了一个名为ID?属性),调用的RenderAction我的POST操作方法,而不是。

Now the problem is that I want the GET action method to be rendered. However (perhaps because the model also contains a property called ID?), Renderaction calls my POST action method instead.

什么是做到这一点的正确方法?我使用ASP.NET MVC 3 RC在它的问题的情况下。

What's the proper way to do this? I'm using ASP.NET MVC 3 RC in case it matters.

谢谢,

阿德里安

推荐答案

问题是,你的看法是回发操作后所呈现。在视图中的所有子动作效果图使用相同的HTTP方法。所以POST正在复制他们。我不知道MVC3,但在MVC2有克服这个问题没有内置的方式。

Sub action uses HTTP method of its parent action

The problem is that your view is being rendered after a postback action. All sub-action renderings in the view use the same HTTP method. So POST is being replicated on them. I'm not sure about MVC3, but in MVC2 there was no built-in way to overcome this problem.

所以,问题是,你希望你的编辑()操作呈现为一个POST视图GET。盒子外面。没办法。

So the problem is that you want your Edit() action to be rendered as a GET on a POST view. Out of the box. No way.

当然你也可以通过提供自己的功能=类做到这一点。

You can of course do it by providing your own functionality = classes.

这篇关于调用的RenderAction错误的操作方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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