![](/img/trans.png)
[英]The current request for action […] on controller type '…' is ambiguous between the following action methods
[英]The current request for action 'Create' on controller type 'WeeklyTargetController' is ambiguous between the following action methods:
我在這里看到了很多這個問題,但我的問題略有不同。 我已經有兩個由MVC開箱即用的創建動作,如此列出(一個是GET,一個是POST):
public ActionResult Create()
{
//stuff...
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include="WeeklyTargetId,UserId,WeekId,Hours")] WeeklyTarget weeklytarget)
{
//stuff...
}
我的問題是我正在嘗試更新基於我已添加到包含在其自己的表單中的頁面的DropDown的創建視圖,在提交時用戶可以過濾主Create表單上的另一個下拉列表。 這是我在Create視圖中單獨包裝的表單:
@using (Html.BeginForm())
{
<p>
<span>
Filter By Practice:
@Html.DropDownList("Practice", (List<SelectListItem>) ViewBag.PracticeList, new { @onchange = "this.form.submit();"})
</span>
</p>
}
我的理由是,當用戶選擇要過濾的練習時,onchange事件將提交表單並啟動我已注銷的新創建操作:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create(FormCollection formCollection)
{
//do the filtering stuff...
}
但是,正如我已經意識到MVC沒有查看方法簽名來覆蓋歧義,並且只能有兩個Create操作。 我有什么選擇? 我完全錯了嗎? 有沒有辦法讓過濾器表單提交路由到一個不同的動作名稱而不是Create? 請記住,這一切都在創建視圖上,之后我會回到這里。 任何幫助將不勝感激,謝謝!
通過BeginForm
方法創建表單時,您可以指定操作和控制器。
Html.BeginForm("FilterAction", "ControllerName")
然后在操作中,您可以通過ViewBag過濾模型中的SelectList中的任何內容。
更多信息可以在這里找到:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.