带重载的Html.BeginForm导致表单动作为'/ cgi-bin?action = Index& controller = Home',因此HomeController被绕过 [英] Html.BeginForm with overload causes form action to be '/cgi-bin?action=Index&controller=Home' and so the HomeController is bypassed

查看:252
本文介绍了带重载的Html.BeginForm导致表单动作为'/ cgi-bin?action = Index& controller = Home',因此HomeController被绕过的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为我想为表单元素分配一个id,我的代码是 @using(Html.BeginForm(null,null,FormMethod.Post,new {id =indexform}))



这导致标记< form action =/ cgi-bin?action = Index& amp; controller = Home 我的HomeController

> ActionResult Index 完全被绕过。



注意'/ cgi-bin'。这可能是问题,我认为罪魁祸首可能是参数'FormMethod.Post',但我不能在这里输入null。



(顺便说一句,使用jQuery var form = $(#btnShowProperty)。closest(form);

I

解决方案

问题在于混合网页和mvc,尤其是使用MapPageRoute和MapRoute在Route.config中。查看完整答案 @ Url.Action(Action,Controller )返回/ cgi-bin?action =动作&控制器=控制器

Because I wanted to assign an id to a form element my code was @using (Html.BeginForm(null, null, FormMethod.Post, new { id = "indexform"}))

This resulted in markup <form action="/cgi-bin?action=Index&amp;controller=Home" id="indexform" method="post" style="position: relative;">

My HomeController ActionResult Index was completely bypassed.

Notice the '/cgi-bin'. This might be the problem and I think the culprit may be parameter 'FormMethod.Post' but I could not enter null there.

(BTW I worked around the id requirement by using jQuery var form = $("#btnShowProperty").closest("form");)

I did quite a bit of Googling on this with no luck.

解决方案

The problem is mixing web pages and mvc especially using MapPageRoute AND MapRoute in Route.config. See full answer @Url.Action("Action", "Controller") returns "/cgi-bin?action=Action&controller=Controller"

这篇关于带重载的Html.BeginForm导致表单动作为'/ cgi-bin?action = Index&amp; controller = Home',因此HomeController被绕过的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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