特定の操作の後に Url を作成しようとしていますが、この URL は別のコントローラーとアクションを指す必要があります。また、必要な情報をターゲット コントローラーに提供するために、いくつかのパラメーターを含める必要があります。だから私はと呼ばれるコントローラを持っているとしましょう:
DoWorkController.cs
そしてアクション
public void Add(params...){..}
次のように、ホームページコントローラーで UriBuilder を使用しています。
UriBuilder builder = new UriBuilder();
builder.Host = System.Web.HttpContext.Current.Request.Url.Host;
builder.Port = System.Web.HttpContext.Current.Request.Url.Port;
//got stuck here
Uri ret = builder.Uri;
return ret;
コントローラー名とアクション名をプルしてビルダーに割り当て、パラメーターを追加したいのですが、これを行う方法がわかりません。提案??
編集
コントローラーからアクションへのパスの問題を解決しましたが、まだURLにパラメーターを追加することに固執しています。
UriBuilder builder = new UriBuilder();
builder.Host = System.Web.HttpContext.Current.Request.Url.Host;
builder.Port = System.Web.HttpContext.Current.Request.Url.Port;
string path;
if (operation == 1)
path = Url.Action("Add", "DoWork");
else if(operation ==2)
path = Url.Action("Delete", "DoWork");
else
throw new ArgumentException("Operation is neither Add or Delete");
if (path != null)
{
builder.Path = path;
}
Uri ret = builder.Uri;