1

我想有一個行動控制器返回另一個actioncontroller partialview。Asp.net mvc 3 - actioncontroller返回partialview另一個actioncontroller

public ActionResult Method1 (string s) 
{ 
return PartialView (_PartialViewMethod1, object1); 
} 

public ActionResult Method2() 
{ 
return PartialViewOfMethod1; 
} 

我在method2上試過這個方法:返回PartialView(Method1(s))但它不起作用,我該如何做到這一點?

感謝

回答

2

試試這個:

public ActionResult Method2() 
{ 
    string s = "someDefinedString"; 

    // instead of return PartialView(Method1(s)); 
    return Method1(s); 
} 
+0

這個方法我試過很短的落實,完美的作品感謝所有 – dtjmsy 2012-04-12 12:37:46

0
public ActionResult Method2() 
{ 
return PartialView ("Method1", object1); 
} 
0

這應該給你你正在尋找

public ActionResult Method2() 
{ 
    return PartialView (_PartialViewMethod1, object1); 
} 

的結果我想你有一些代碼,你也參加了對於這兩種行動方法,這就是爲什麼你想調用另一個行動,那麼你可能會把它移動到一個通用的方法od,並從任何你想要的地方撥打電話。一些反應!

public YourViewModel GetData(srting s="") 
{ 
    YourViewModel obj1=new YourVieWModel() 
    // set some property values or do some operations to get data 
    //your custom code 
    return obj1; 
} 

public ActionResult Method1 (string s) 
{ 
    return PartialView (_PartialViewMethod1, GetData(s)); 
} 

public ActionResult Method2() 
{ 
    return PartialView (_PartialViewMethod1, GetData()); 
} 
+0

我學習的東西日常的感謝Shyju – dtjmsy 2012-04-12 12:38:24

+0

我不知道object1直到我打電話方法1 – dtjmsy 2012-04-12 12:39:42

相關問題