2012-05-05 6 views
0

ビューにモデルと別のパラメータを渡すために...と私は単純な何かが欠けているかもしれないが、基本的に私はこれを行うことができるようにしたいどのように...私はすでにこれを行っていること

public ActionResult ContinueProcess(Model m, int id){ 


} 

私はモデルと別のパラメータを同時に渡したいだけです。何かご意見は?ありがとう!

答えて

1

私は確かにこの

を処理するために のViewModelを作成します
public class ContinueProcessViewModel 
{ 
    public int ID { set;get;} 
    public Model ContinueProcess { set;get;} 
} 
あなたのgetアクションメソッド」

public ActionResult ContinueProcess(int id) 
{ 
    ContinueProcessViewModel objVM=new ContinueProcessViewModel(); 
    objVm.ID=id; 
    return View(objVM); 
} 

そして、あなたのビューの中

戻るこのViewModelに、この

@Html.HiddenFor(x=>x.ID) 

の値を保持するためのHtmlElement(テキストボックス/隠された)を持っている今、あなたはできるはずですあなたのhttppostアクションメソッドでこれを実現するには

[HttpPost] 
public ActionResult ConitnueProcess(ContineProcessViewModel objVM) 
{ 
    //Check objVm.ID here 
} 
3

どちらかのViewModel

public class MyViewModel { 
    public Model MyModel {get;set;} 
    public int ParameterId {get;set;} 
} 

、あなたのビューのモデルとして使用

かと

ViewBag

ViewBag.ParameterId= id; 
関連する問題