Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 如何在不同的控制器中返回视图_Asp.net Mvc - Fatal编程技术网

Asp.net mvc 如何在不同的控制器中返回视图

Asp.net mvc 如何在不同的控制器中返回视图,asp.net-mvc,Asp.net Mvc,这是可行的,但如果它位于不同的视图文件夹中,为什么不可行呢?我是不是错过了什么 请注意ASP.net新手 问候 Vinay您可以重定向到操作: Class Student { String Name {get; set} //Extended property of the student School Shooling {get; set;} } public StudentControlelr () { public SchoolInfo (int? ID)

这是可行的,但如果它位于不同的视图文件夹中,为什么不可行呢?我是不是错过了什么

请注意ASP.net新手

问候
Vinay

您可以重定向到操作:

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);
这里唯一的问题是您无法传递模型,但有两种方法可以解决此问题:

传递参数并在加载时获取模型

return RedirectToAction("Action", "Controller");
使用TempData传递模型

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

您可以重定向到操作:

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);
这里唯一的问题是您无法传递模型,但有两种方法可以解决此问题:

传递参数并在加载时获取模型

return RedirectToAction("Action", "Controller");
使用TempData传递模型

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

这将起作用,但更好的解决方案是重定向到不同的操作:

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

注意:如果不使用aspx视图,则需要将.aspx更改为视图扩展。

这将起作用,但更好的解决方案是重定向到其他操作:

TempData["MyModel"] = s.Schooling;
return RedirectToAction("Action", "Controller");
注意:如果不使用aspx视图,则需要将.aspx更改为视图扩展名