HTMLAction-获取与发布 [英] Html.Action - Get versus Post

查看:111
本文介绍了HTMLAction-获取与发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常这样做:

<div id='Product'>
@Html.Action("Create", "Product")
</div>

这很方便,因为我可以将产品创建表单的绘画委派给另一个控制器动作以嵌入到位置.但是,我有一个问题,就是该方法有时会(我还没有弄清楚在什么条件下)会调用我的控制器操作的[HttpPost],这当然会失败.

it's convenient because I can delegate the painting of a product creation form to another controller action for embedding in places. However, I'm having issues in that the method will sometimes (I haven't figured out under what conditions) call the [HttpPost] of my controller action, which of course fails.

有没有办法强制@ Html.Action()调用GET版本?

Is there a way to force @Html.Action() to call the GET version?

推荐答案

Html.Action的工作方式是,如果当前对页面的请求是post方法,则它将搜索名称为HttpPost的方法.

The way Html.Action works is that if the current request for the page is a post method then it will search for the method with the name HttpPost.

因此,正在发生的事情是您正在发布当前页面,并且该操作同样假定所有应执行的操作也必须是POST.

So what's happening is that you're POSTing the current page and the action likewise assumes all actions that should execute must be a POST too.

我没有办法强迫它切换到类似的方法.

There's no way I know of to force it to switch to a different method like that.

这篇关于HTMLAction-获取与发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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