0

私には2つの方法があります:

public ActionResult Index(int? id)
{
    return Redirect("/View/" + this.GetMenuItems().First().Id);
}

public ActionResult Index(int id, uint? limit)
{

/View/1に移動すると、そのエラーが発生します

コントローラー タイプ 'ViewController' のアクション 'Index' に対する現在の要求は、次のアクション メソッド間であいまいです: System.Web.Mvc.ActionResult Index(System.Nullable 1[System.Int32]) on type SVNViewer.Controllers.ViewController System.Web.Mvc.ActionResult Index(Int32, System.Nullable1[System.UInt32]) on type SVNViewer.Controllers.ViewController

その2つの方法が必要ですが、あいまいなエラーを削除するにはどうすればよいですか?

4

3 に答える 3

2

2 番目のアクションを変更して、null 許容 uint を持たないようにします。

public ActionResult Index(int id, uint limit)

limitIndex(int? id)が null の場合に処理するメソッドにする必要があります。

于 2012-10-11T14:09:35.060 に答える
2

これを回避するには、ActionName を使用できます。 ActionNameの目的

両方が同じことを行う場合は、代わりに次のことを行うことができます。

public ActionResult Index(int? id, uint? limit = null)
{
  ...
}

2 番目のパラメーターをオプションにします。

または、1 つが [HttpGet] 属性を持ち、もう 1 つが [HttpPost] 属性を持つようにします (一方が get に応答し、もう一方が投稿されたフォームに応答する場合)。

于 2012-10-11T14:09:53.527 に答える
1

モデルを作成して、アクションメソッドを1つだけ持つことができます。

public class MyActionModel 
{
    public int? Id { get;set; }
    public int? Limit { get;set; }
}

次に、コントローラーで:

public ActionResult Index(MyActionModel model)
{
    // Your code here
    if (model.Id.HasValue() { // do something....etc}
}
于 2012-10-11T14:15:30.070 に答える