C# MVC2中的Ajax.begin Bug??Ajax发布到错误的控制器?
我正在使用一个ajax表单,试图使用Create方法向CustomerController发回消息。这是密码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
<% 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" }))