[英]How to return View into another project (modules) in .net core web application
I am setting up an architecture like modular programming, But I would like to return the view from one project to another project. 我正在建立一种类似于模块化编程的体系结构,但是我想将视图从一个项目返回到另一个项目。
I had tried with the codes which i have found from, 我尝试使用从中找到的代码,
Project structure may like, 项目结构可能像
WebApplicaitonModule1
Controllers
Views
Layouts
WebApplicationModule2
Controllers
Views
Layouts
WebApplicationModule3
Controllers
Views
Layouts
WebApplicationModule4
Controllers
Views
Layouts
Models and DAL are different libraries
I need something like, how to redirect/return the View from Module1 to the view of Module2's Page?. 我需要类似的东西,如何将视图从Module1重定向/返回到Module2页面的视图? is that possible in .net core applications. .net核心应用程序有可能做到这一点。 I am using .net core 2.1. 我正在使用.net core 2.1。
Because the I need to get the layout differently in Module wise. 因为我需要在Module明智地获得不同的布局。
My Imaginary scenario,
- In WebApplicationModule2 we have a action like this and it will return the view.
public IActionResult Index()
{
model objmodel = new model();
return View("~/Home/Index.cshtml",objmodel );
}
then after adding Project Dependency,
- from WebApplicationModule1
public IActionResult Index()
{
model objmodel = new model(); // same model return from another project.
return View("~/WebApplicationModule2/Home/Index.cshtml",objmodel );
}
How can we achieve this? 我们怎样才能做到这一点? or is there any other ways to do this? 还是有其他方法可以做到这一点? Any help is appreciate. 任何帮助表示赞赏。
I think you can use redirect to route like this. 我认为您可以使用重定向来进行这样的路由。 I'm not know about your controller name so you need to pass in controller you want to redirect to and the model you want to pass in that controller method 我不知道您的控制器名称,因此您需要传入要重定向到的控制器,以及传入该控制器方法的模型
return RedirectToRoute(new
{
controller = "",
action = "Index",
model = model
});
Please let me know if you need any help. 如果您需要任何帮助,请告诉我。 Cheers 干杯
Add the child projects as Razor Class Library. 将子项目添加为Razor类库。
Add as Project reference( This will include all the reference files which used in the Razor class library project) or as an assembly reference( which contains only the .dll and view.dll) 添加为项目参考(将包括Razor类库项目中使用的所有参考文件)或作为程序集参考(仅包含.dll和view.dll)
and then it will be easily we can call the views( better if we added as Area wise), 然后我们可以很容易地调用视图(最好将其添加为Area明智),
In WebApplicationModule2 we have an action like this and it will return the view.
public IActionResult Index()
{
model objmodel = new model();
return View("~/Home/Index.cshtml",objmodel );
}
Add as project reference or assmebly reference then from WebApplicationModule1. 然后从WebApplicationModule1中添加为项目参考或组装参考。
public IActionResult Index()
{
model objmodel = new model(); // same model return from another project.
return View("~/WebApplicationModule2/Home/Index.cshtml",objmodel );
}
the passing model should be the same. 传递的模型应该相同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.