Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MVC2中的Ajax.begin Bug??Ajax发布到错误的控制器?_C#_Asp.net Mvc_Asp.net Mvc 2 - Fatal编程技术网

C# MVC2中的Ajax.begin Bug??Ajax发布到错误的控制器?

C# MVC2中的Ajax.begin Bug??Ajax发布到错误的控制器?,c#,asp.net-mvc,asp.net-mvc-2,C#,Asp.net Mvc,Asp.net Mvc 2,我正在使用一个ajax表单,试图使用Create方法向CustomerController发回消息。这是密码 <% using (Ajax.BeginForm("Create", "Customer", new AjaxOptions { LoadingElementId = "saving"}, new { @class = "block_content form" })) {%>... 。。。 当我的html表单呈现时,表单如下所示 <form onsu

我正在使用一个ajax表单,试图使用Create方法向CustomerController发回消息。这是密码

<% using (Ajax.BeginForm("Create", "Customer", new AjaxOptions { LoadingElementId = "saving"}, new { @class = "block_content form" }))
        {%>...
。。。
当我的html表单呈现时,表单如下所示

<form onsubmit="Sys.Mvc.AsyncForm.handleSubmit(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, loadingElementId: 'saving', onComplete: Function.createDelegate(this, $j('#accoutcreate').dialog('close')) });" onclick="Sys.Mvc.AsyncForm.handleClick(this, new Sys.UI.DomEvent(event));" method="post" class="block_content form" action="/Job/Create?Length=3"> ...
。。。
如您所见,表单实际上是发布到/Job/Create而不是/Customer/Create


我不知道为什么会这样。有什么想法吗?

您是否可以在Global.asax中设置路由,将“\Job”请求映射到“CustomerController”?如果是这样,MVC中的路由引擎将返回“\Job”作为URL,以保持URL的一致性

路线看起来像这样:

        routes.MapRoute("Name", "Job/Create", new { controller = "Customer", action = "Create" });

是否可以在Global.asax中设置路由,将“\Job”请求映射到“CustomerController”?如果是这样,MVC中的路由引擎将返回“\Job”作为URL,以保持URL的一致性

路线看起来像这样:

        routes.MapRoute("Name", "Job/Create", new { controller = "Customer", action = "Create" });

我猜,框架采取了不合适的方法。 也许是这样:

public static MvcForm BeginForm(this AjaxHelper ajaxHelper,
string actionName, object routeValues, AjaxOptions ajaxOptions,
object htmlAttributes);
您提供了:

"Create" - actionName,   "Customer" - routeValues,   new AjaxOptions(..) - ajaxOptions,   new { @class = "block_content form" }
- htmlAttributes.
请注意,
routeValues
具有对象类型和“Customer”字符串,对于C#编译器来说一切都正常,但对于您来说则不然

试着写:

(Ajax.BeginForm("Create", "Customer", null,
new AjaxOptions { LoadingElementId = "saving"}
new { @class = "block_content form" }))

我猜,框架采取了不合适的方法。 也许是这样:

public static MvcForm BeginForm(this AjaxHelper ajaxHelper,
string actionName, object routeValues, AjaxOptions ajaxOptions,
object htmlAttributes);
您提供了:

"Create" - actionName,   "Customer" - routeValues,   new AjaxOptions(..) - ajaxOptions,   new { @class = "block_content form" }
- htmlAttributes.
请注意,
routeValues
具有对象类型和“Customer”字符串,对于C#编译器来说一切都正常,但对于您来说则不然

试着写:

(Ajax.BeginForm("Create", "Customer", null,
new AjaxOptions { LoadingElementId = "saving"}
new { @class = "block_content form" }))