私は MVC3 Web アプリケーションを構築しており、knockoutjs を使用しています。アプリケーションには 2 つのビューがあります。SetUpNewCompany と ManageAccount。新しい会社を設定するには、ユーザーは最初にアカウント番号を入力し、検索をクリックします。アカウント番号が既に存在する場合、ユーザーはボタンをクリックして ManageAccount ビューに移動できます。SetUpNewCompanyController では、RedirectToAction メソッドを使用してリダイレクトします。ただし、ManageAccount の Index2 アクションが実行されると、ビューは表示されません。完全な URL を入力すると、ビューが表示されます。
SetUpNewCompanyController.cs
[HttpPost]
public RedirectToRouteResult RedirectToManageAccount(string accountNumber)
{
return RedirectToAction("Index2", new RouteValueDictionary(new {controller=
"ManageAccount", companyId = "7e96b930-a786-44dd-8576-052ce608e38f" }));
}
上記は、ボタンがクリックされたときに以下の関数によって呼び出されます
self.redirectToManageAccount = function () {
var accountNumber = "7e96b930-a786-44dd-8576-052ce608e38f";
$.ajax({
type: "POST",
url: "/SetUpNewCompany/RedirectToManageAccount",
data: { accountNumber: accountNumber },
success: function (data) {
},
error: function () {
}
});
}
ManageAccountController.cs
public ActionResult Index2(String companyId)
{
var viewModel = new Models.Index();
List<String> compList = new List<String>();
compList.Add("MyCompany");
List<String> usersList = new List<String>();
usersList.Add("User1");
viewModel.Users = usersList;
viewModel.Companies = compList;
viewModel.CompanyId = companyId;
viewModel.Role = "Role1";
return View("ManageAccount",viewModel);
}
生成される URL は
http://localhost:53897/ManageAccount/Index2?companyId=7e96b930-a786-44dd-8576-
052ce608e38f
Firebug のコンソール ウィンドウが表示されます
GET http://localhost:53897/ManageAccount/Index2?companyId=7e96b930-a786-44dd-8576-
052ce608e38f 200 OK and the spinner keeps spinng
また、クエリ文字列の代わりに以下の URL を取得するにはどうすればよいですか
http://localhost:53897/ManageAccount/Index2/7e96b930-a786-44dd-8576-052ce608e38f