2016-09-29 3 views
0

Url.Action()を除き、アクションのためにRedirectResultを返したいとします。私は次のものを持っているとしよう:ControllerReturn ActionResult as 301

public class CustomerController : Controller 
{ 
    public ActionResult Index() 
    { 
     var url = Url.Action("CustomerAndProduct", new { customerId = 1, orderId = 2, productId = 3}); 
     return Redirect(url); 
    } 

    public ActionResult CustomerAndProduct(int customerId, int orderId, int productId) 
    { 
     // I want to get here... 
    } 
} 

私は手動で文字列を使用して、アクション名とすべてのパラメータの両方を指定せずにRedirectResultを返すことができる方法はありますか?その理由は、アクション名またはパラメータ名が変更された場合、これらの文字列を維持するのが面倒だと感じているからです。コンパイル時には検出されません。おそらく、そのような

var url = Url.FromAction<CustomerController>(x => x.CustomerAndProduct(1, 2, 3)); 
return Result(url); 

1は、Futures libraryで行うことができる非常に多くのように:私はCustomerAndProductを実行したくない

Html.BeginForm<CustomerController>(x => x.CustomerAndProduct(1, 2, 3)) 

注意。私はちょうど301または302としてURLを返すしたいと思います。

答えて

1

タイプセーフティを求めているようですね。もしそうなら、t4MVCを見てください

return RedirectToAction(MVC.Customer.CustomerAndProduct(1,2,3)); 
+0

100+クラブへようこそ。 ;) 良い例え。しかし、私は第三者を最小限に抑えようとしており、既にFuturesを使用しています。これは、ほとんどのヘルパーにとって同じことを提供します。 – smoksnes

関連する問題