Html.Action - Get versus Post

﹥>﹥吖頭↗ 提交于 2019-12-03 09:58:54

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.

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.

Champ

Try adding the AcceptVerbs attribute to your action:

[AcceptVerbs(HttpVerbs.Get|HttpVerbs.Post)]
public ActionResult Create()
{
    //Your code
}

This will work for both GET and POST requests.

Steve

I also got into a similar problem and there indeed is a solution. Just Check whether Request is get or POST in View using IsPost Property and VOILA....

@if(!IsPost)    
{    
    HTML.Action("ActionName")    
}

Regards to whoever got in similar problem...

I just encountered this issue, which was hard to identify. I ended up using Html.RenderPartial instead, like this:

<div id='Product'>
@{Html.RenderPartial("_CreatePartial", new Product());}
</div>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!