簡體   English   中英

MVC2中的Ajax.BeginForm錯誤? Ajax發布到錯誤的控制器?

[英]Ajax.BeginForm Bug in MVC2?? Ajax for Posting to Wrong Controller?

我正在使用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的

我不確定為什么會這樣。 有任何想法嗎?

我猜想,框架沒有采取適當的方法。 也許這樣:

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具有對象類型和“客戶”-字符串,對於C#編譯器來說一切正常,但對您而言不是。

嘗試寫:

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

是否有可能在Global.asax中設置了將“ \\ Job”請求映射到“ CustomerController”的路由設置? 如果是這樣,MVC中的路由引擎將返回“ \\ Job”作為URL,以保持URL的一致性。

路線如下所示:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM