2011-03-08 92 views
0
Class Student { 
    String Name {get; set} 

    //Extended property of the student 
    School Shooling {get; set;} 
} 


public StudentControlelr() 
{ 

public SchoolInfo (int? ID) 
{ 
     Student s = StudentRepository.GetStudentByID(id) 
     Return View ("Schooling/Index", s.Schooling); 
} 

} 

for some reason i have to make this view as a shared view 
// Views/Shared/schooling.ascx 
Return View ("Schooling", s.Schooling); 

这可行,但为什么不,如果它在不同的视图文件夹中不起作用?我在这里错过了一些东西吗?如何在不同的控制器中返回一个视图

请注意,ASP.net新手。

亲切的问候 维奈

回答

3

您可以重定向到行动:

return RedirectToAction("Action", "Controller"); 

这里唯一的问题是,你不能传递一个模式,但有几个方法来解决这个问题:

传递参数,并得到在负荷模型

return RedirectToAction("Action", "Controller", new { id = 1}); 

传递使用的TempData

TempData["MyModel"] = s.Schooling; 
return RedirectToAction("Action", "Controller"); 
0

这将工作模式,而是一个更好的解决办法是将重定向到一个不同的动作:

return View ("~/Views/Schooling/Index.aspx", s.Schooling); 

注意:您需要的.aspx更改为如果您不使用ASPX视图,则可以使用您的视图扩展名。

相关问题