2017-10-23 3 views
0
Url.Action("CreatePerson", "Person", new { id = 6, name = "rachel", grade="a" }); 

は、私が最初の値のみ(idの値)を取得するが、私はnamegradeの値を得ることはありません。どうして?あなたが明示的ルート・パラメータを定義する必要があり、時にはまたUrl.Actionでいくつかのパラメータを渡すには?私はアクションのパラメータを取得すると

@Viewbag.name 

:あなたは値を表示することができます

public ActionResult SuccessfulPostData(int id, string name, string grade) 
     { 

      ViewBag.name= name; 
      return View(); 
     } 

を見るには:

+0

https://stackoverflow.com/questions/24178320/how-to-send-multiple-parameter-in-url-action –

+0

ポストあなたのコントローラ –

+0

公共のActionResult人(int型のID = 0、文字列名= ""、文字列グレード= "") { return PartialView( "Success"); } – Rachel

答えて

0

あなたがそうのようなコントローラのメソッドに追加パラメータを定義する必要があります。これはRouteConfig.csファイルにあります。

routes.MapRoute(
     name: "Default", 
     url: "{controller}/{action}/{id}/{name}/{grade}", 
     defaults: new { controller = "Home", action = "SuccessfulPostData", id = UrlParameter.Optional, name = UrlParameter.Optional, grade = UrlParameter.Optional } 
    ); 
関連する問題